Using WriteCodeFragment MSBuild Task

2019-01-29 06:09发布

问题:

I am trying to use WriteCodeFragment MSBuild task to create AssemblyVersion attribute. I'm having a a problem creating a property group to correctly pass the ITaskItem array required for processing. Can someone help with an example.

回答1:

This worked and created a BuildVersion.cs file with correct AssemblyVersion attribute of 123.123.123.123

<Target Name="BeforeBuild">
  <ItemGroup>
     <AssemblyAttributes Include="AssemblyVersion">
       <_Parameter1>123.132.123.123</_Parameter1>
     </AssemblyAttributes>
  </ItemGroup>
  <WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)"
                     Language="C#"
                     OutputDirectory="$(IntermediateOutputPath)">
    <Output TaskParameter="OutputFile" ItemName="Compile" />
  </WriteCodeFragment>
</Target>