Question

[assembly: AssemblyCopyright("Copyright ©  2009")]

is it possible somehow to access functions like DateTime.Now.Year inside the AssemblyInfo class? so as to put in like

[assembly: AssemblyCopyright("Copyright ©  " + DateTime.Now.Year)]

Doing the above will give, DateTime does not exist in the current context

Was it helpful?

Solution

Out of the box, no, but there are 2 options to access .NET functionality against your assembly file.

The easiest way to do your example would be to use the AssemblyInfo task from the MSBuildExtensionPack.

Once you have that installed you can use all the methods in that Task, http://www.msbuildextensionpack.com/help/4.0.4.0/index.html, such as the following:

    <Target Name="Version">
    <ItemGroup>
        <AssemblyInfoFiles Include="$(SourcePath)\Code\Properties\AssemblyInfo.cs"/>
    </ItemGroup>
    <MSBuild.ExtensionPack.Framework.DateAndTime TaskAction="Get" Format="yyyy">
        <Output TaskParameter="Result" PropertyName="MyStartTime"/>
    </MSBuild.ExtensionPack.Framework.DateAndTime>
    <MSBuild.ExtensionPack.Framework.AssemblyInfo ComVisible="false" AssemblyInfoFiles="@(AssemblyInfoFiles)" AssemblyBuildNumberType="YearWeekDay" FirstDayOfWeek="Sunday" AssemblyBuildNumber="4" AssemblyCopyright=" Foo Copyright $(MyStartTime)"/>
</Target>

The other option is to create a custom msbuild task on your own and expose additional functionality that way.

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