Question

Is there a MSBuild task for setting custom attribute in AssemblyInfo.cs? I found AssemblyInfo task but it seems that it cannot set custom attributes, only predefined ones. I'd like to set 3 custom properties I have added into this file.

Any suggestion how to solve this?

Was it helpful?

Solution

WriteCodeFragment task can help:

<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>

OTHER TIPS

Look at the file: Microsoft.NET.GenerateAssemblyInfo.targets.

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

So, you should use AssemblyAttribute and not AssemblyAttributes.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top