用于在AssemblyInfo.cs中设置自定义属性的MSBuild任务

时间:2012-06-11 12:37:19

标签: c# msbuild-task msbuildcommunitytasks pre-build-event

是否有用于在AssemblyInfo.cs中设置自定义属性的MSBuild任务? 我找到了AssemblyInfo任务,但它似乎无法设置自定义属性,只能预定义属性。我想设置3个已添加到此文件中的自定义属性。

有任何建议如何解决这个问题?

2 个答案:

答案 0 :(得分:12)

WriteCodeFragment任务可以提供帮助:

<Target Name="BeforeBuild">
    <ItemGroup>
     <AssemblyAttributes Include="AssemblyTitle">
        <_Parameter1>My Assembly</_Parameter1>
     </AssemblyAttributes>
     <AssemblyAttributes Include="AssemblyDescription">
        <_Parameter1>My Assembly</_Parameter1>
     </AssemblyAttributes>  
     <AssemblyAttributes Include="AssemblyCompany">
        <_Parameter1>My Company</_Parameter1>
     </AssemblyAttributes>
     <AssemblyAttributes Include="AssemblyProduct">
        <_Parameter1>My Product</_Parameter1>
     </AssemblyAttributes>
     <AssemblyAttributes Include="AssemblyCopyright">
        <_Parameter1>Copyright © 2012</_Parameter1>
     </AssemblyAttributes>
     <AssemblyAttributes Include="AssemblyCulture">
        <_Parameter1></_Parameter1>
     </AssemblyAttributes>       
     <AssemblyAttributes Include="AssemblyVersion">
        <_Parameter1>1.0.0.0</_Parameter1>
     </AssemblyAttributes>   
     <AssemblyAttributes Include="AssemblyFileVersion">
        <_Parameter1>1.0.0.0</_Parameter1>
     </AssemblyAttributes>
     <AssemblyAttributes Include="System.Runtime.InteropServices.Guid">
        <_Parameter1>e7a979b2-0a4f-483a-ba60-124e7ef3a931</_Parameter1>
     </AssemblyAttributes>
    </ItemGroup>
  <WriteCodeFragment Language="C#" OutputFile="Properties/AssemblyInfo.cs" AssemblyAttributes="@(AssemblyAttributes)" />
</Target>

答案 1 :(得分:0)

查看文件:Microsoft.NET.GenerateAssemblyInfo.targets

<WriteCodeFragment AssemblyAttributes="@(AssemblyAttribute)" Language="$(Language)" OutputFile="$(GeneratedAssemblyInfoFile)">
  <Output TaskParameter="OutputFile" ItemName="Compile" />
  <Output TaskParameter="OutputFile" ItemName="FileWrites" />
</WriteCodeFragment>

因此,您应该使用AssemblyAttribute而不是AssemblyAttributes