我正在尝试使用WriteCodeFragment MSBuild任务来创建AssemblyVersion属性。我在创建属性组时遇到问题,无法正确传递处理所需的ITaskItem数组。有人可以帮助一个例子。
这将创建一个名为BuildVersion.cs
的文件,其AssemblyVersion
属性为123.123.123.123
。如果删除OutputFile
,则将使用随机生成的文件名。 Compile
项目名称会自动将项目添加到Compile项目(包括构建中的BuildVersion.cs
)。 FileWrites
项目名称允许在Clean期间删除文件。
<Target Name="BeforeBuild">
<ItemGroup>
<AssemblyAttributes Include="AssemblyVersion">
<_Parameter1>123.123.123.123</_Parameter1>
</AssemblyAttributes>
</ItemGroup>
<WriteCodeFragment AssemblyAttributes="@(AssemblyAttributes)"
Language="C#"
OutputDirectory="$(IntermediateOutputPath)"
OutputFile="BuildVersion.cs">
<Output TaskParameter="OutputFile" ItemName="Compile" />
<Output TaskParameter="OutputFile" ItemName="FileWrites" />
</WriteCodeFragment>
</Target>