문제

[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