zoukankan      html  css  js  c++  java
  • [Learn Note] MSBuild

    1 基本定义

    属性是键/值的配对,相应于:

    环境变量项目文件自身中的定义使用 /p 传递给 msbuild.exe 的命令行参数

    2 项

    <Item Type="FilesToCompile" Include="file1.cs"/>  
    <Item Type="FilesToCompile" Include="file2.cs"/>  
    <Item Type="FilesToCompile" Include="file3.cs"/>
    <Item Type="FilesToCompile" Include="*.cs"/>
    <Item Type="FilesToCompile" Include="file1.cs;file2.cs;file3.cs" />
    <Item Type="FilesToCompile" Include="*.cs" Exclude="Bad*.cs"/>

    3 任务和属性

    项可以用作任务的输入。相应的 XML Task 元素有一个强制的属性:它的 Name 属性。您为该属性设置的值会告诉引擎要执行的任务的种类。MSBuild 提供了几个现成可用的任务,例如 Copy、Csc、Exec、MakeDir、MSBuild、ResGen 和 Vbc。

    <Item Type="FilesToCompile" Include="*.cs"/>  
    
    <Target Name="BuildHelloWorldExecutable">
       <Task 
          Name="csc" 
          Sources="@(FilesToCompile)"
          OutputAssembly="HelloWorld.exe"
          TargetType="exe"
       />
    </Target>
    <Project>
       <Property 
          ExecutableName="HelloWorld" 
       />
       <Property 
          OutputPath="bin" 
       />
    
       <Item 
          Type="FilesToCompile" 
          Include="*.cs"
       />  
    
       <Target Name="BuildHelloWorldExecutable">
          <Task
             Name="MakeDir"
             Directories="$(OutputPath)"
          />
          <Task 
             Name="csc" 
             Sources="@(FilesToCompile)"  
             OutputAssembly="$(OutputPath)\$(ExecutableName).exe"
             TargetType="exe"
          />
       </Target>
    </Project>

    4 使用条件进行选择

    <PropertyGroup Condition="'$(Configuration)'=='DEBUG'">
       <Property OutputPath="bin\debug" />
       ...
    </PropertyGroup>
    
    <PropertyGroup Condition="'$(Configuration)'=='RELEASE'">
       <Property OutputPath="bin\release" />
       ...
    </PropertyGroup>

    5 Summary

    属性是指定输入参数,任务是实际的过程,从属于一个特定的目标

    可以改变Visual Studio MSBuild的设置,了解编译的过程 Options->Projects and Solutions->Build and Run->MSBuild…

    任务就是 MSBuild 中的基本生成块。Target 将任务以特殊顺序组合在一起。它的 Name 是唯一的强制属性,因为您需要能够在命令行使用 /t 开关传递该属性,或者在 Project XML 根节点的 DefaultTargets 属性中传递该属性,这样才能使 MSBuild 知道要执行的任务。在项目文件中,Tasks 元素的定义顺序非常重要,因为 MSBuild 每次针对给定目标执行一个任务。

    6 Reference:

    6.1 msdn
    6.2 MSBuild Overview

    Post by: Jalen Wang (转载请注明出处)

  • 相关阅读:
    反转链表 --剑指offer
    链表的倒数第K个节点
    打印1到最大的n位数----java实现
    Permutations java实现
    Generate Parentheses java实现
    Binary Tree Level Order Traversal java实现
    hadoop中日志聚集问题
    PIG的配置
    hadoop2.20.0集群安装教程
    Map/Reduce之间的Partitioner接口
  • 原文地址:https://www.cnblogs.com/jalenwang/p/2353151.html
Copyright © 2011-2022 走看看