Benutzer:MovGP0/NET/MSBuild

aus Wikipedia, der freien Enzyklopädie
   MovGP0        Über mich        Hilfen        Artikel        Weblinks        Literatur        Zitate        Notizen        Programmierung        MSCert        Physik      

MSBuild

Targets and Task

  • Target executes a series of tasks
  • MSBuild Task Reference. In: MSDN. Microsoft, abgerufen am 3. September 2014 (englisch).
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="HelloWorld">
    <Message Text="Hello World!" />
  </Target>
</Project>
 
msbuild myproject.msproj /target:HelloWorld

Properties

Define Properties
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AppServer>\\app.server</AppServer>
    <WebServer>\\web.server</WebServer>
  </PropertyGroup>
</Project>

equal to:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <AppServer>\\app.server</AppServer>
  </PropertyGroup>
  <PropertyGroup>
    <WebServer>\\web.server</WebServer>
  </PropertyGroup>
</Project>
Using Properties
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <HelloMessage>Hello World!</HelloMessage>
  </PropertyGroup>
  <Target Name="HelloWorld">
    <Message Text="$(HelloMessage)" />
  </Target>
</Project>
 
msbuild myproject.msproj /t:HelloWorld

Items

  • @(ItemType)
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <SolutionFile Include="..\MySolution.sln" />
    <Compile Include="Program.cs;Properties\AssemblyInfo.cs" />
    <Compile Include="MainForm.cs" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="MainForm.Designer.cs">
       <DependentUpon>MainForm.cs</DependentUpon> <!-- File nesting -->
    </Compile>
  </ItemGroup>
  <Target Name="PrintInfo">
    <Message Text="SolutionFile: @(SolutionFile)" />
    <Message Text="Files to Compile: @(Compile)" /> <!-- Program.cs;Properties\AssemblyInfo.cs;MainForm.cs;MainForm.Designer.cs -->
  </Target>
</Project>

Item Metadata

<Project DefaultTargets="PrintMetadata" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
   <ItemGroup>
      <Compile Include="MyClass.cs" />
   </ItemGroup>
   <Target Name="PrintMetadata">
      <Message Text="%40(Compile->'%25(FullPath)')" />
   </Target>
</Project>

Conditions

MSBuild Conditions
Condition Description
== True when both are the same value
!= True when different
Exists(...) True when path (file) exists
!Exists(...) True when path (file) does not exist
<Project DefaultTargets="PrintContent" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup Condition="$(Configuration) == ''"> <!-- set only when not already set -->>
    <Configuration>Release</Configuration>
  </PropertyGroup>
  <ItemGroup>
    <Content Include="script.js" />
    <Content Include="script.debug.js" Condition="$(Configuration) == 'Debug'" />
  </ItemGroup>
  <Target Name="PrintContent">
    <Message Text="Configuration: $(Configuration)" />
    <Mesage Text="Content: @(Content)" /> <!-- script.js -->
  </Target>
</Project>