[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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top