我试图设置一个csproj,汇编信息由编译日期时间和 mercurial修订版自动生成。
<!-- assembly info -->
<PropertyGroup>
<!-- versioning number: Maj.Min.TimeStamp.Rev -->
<Major>2</Major>
<Minor>90</Minor>
<!-- define Build based on the compilation date: yyddd that sould be integer in [0..65535] -->
<Build>$([System.DateTime]::Now.ToString(`yy`))$([System.DateTime]::Now.DayOfYear.ToString(`000`))</Build>
<Revision>0</Revision>
<Version>$(Major).$(Minor).$(Build)</Version>
<AssemblyVersion>$(Major).$(Minor).$(Build).$(Revision)</AssemblyVersion>
<FileVersion>$(Major).$(Minor).$(Build).$(Revision)</FileVersion>
</PropertyGroup>
<Import Project="..\packages\MSBuild.Mercurial.1.2.1\build\MSBuild.Mercurial.targets" Condition="Exists('..\packages\MSBuild.Mercurial.1.2.1\build\MSBuild.Mercurial.targets')" />
<Target Name="GetHgRev" BeforeTargets="GenerateAssemblyInfo" DependsOnTargets="PrepareForBuild">
<HgVersion LocalPath="$(SolutionDir)" Timeout="5000">
<Output TaskParameter="Revision" PropertyName="Revision" />
</HgVersion>
<Message Text="Last revision from HG: $(Revision)" Importance="High" />
<Message Text="$(Major).$(Minor).$(Build).$(Revision)" Importance="High" />
</Target>
在控制台输出中,我得到了一些一致的东西。2.90.20160.239But只有$(Build)在tmp AssemblyInfo.cs中被正确使用,$(Revision)基本为0。
在以前的csproj格式(2015年)中,我在BeforeBuild目标中用显式cmd就能完成工作。
<PropertyGroup>
<AssemblyCompany>AAA</AssemblyCompany>
<MyAppName>BBB</MyAppName>
<Major>2</Major>
<Minor>90</Minor>
<Build>0</Build>
<Revision>0</Revision>
</PropertyGroup>
<Target Name="BeforeBuild">
<!-- get the Mercurial revision no -->
<HgVersion LocalPath="$(SolutionDir)" Timeout="5000">
<Output TaskParameter="Revision" PropertyName="Revision" />
</HgVersion>
<Message Text="Last revision from HG: $(Revision), today date $([System.DateTime]::Now.ToString(`yyyy.MM.dd`)) -> $([System.DateTime]::Now.ToString(`yy`))$([System.DateTime]::Now.DayOfYear.ToString(`000`))" Importance="High" />
<!-- define Build based on the compilation date: yyddd that sould be integer in [0..65535] -->
<CreateProperty Value="$([System.DateTime]::Now.ToString(`yy`))$([System.DateTime]::Now.DayOfYear.ToString(`000`))">
<Output PropertyName="Build" TaskParameter="Value" />
</CreateProperty>
<!-- generate version file, i.e. AssemblyInfo.cs used later for compilation -->
<Message Text="Creating Version File: $(Major).$(Minor).$(Build).$(Revision)" Importance="High" />
<AssemblyInfo CodeLanguage="CS" OutputFile=".\Properties\AssemblyInfo.cs" AssemblyTitle="AAA" AssemblyDescription="BBB" AssemblyCompany="$(AssemblyCompany)" AssemblyProduct="CCC" AssemblyCopyright="Copyright © DDD $([System.DateTime]::Now.ToString(`yyyy`))" AssemblyVersion="$(Major).$(Minor).$(Build).$(Revision)" AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
</Target>
你看这个问题有什么解决方法吗?
新的测试。
<Import Project="..\packages\MSBuild.Mercurial.1.2.1\build\MSBuild.Mercurial.targets" Condition="Exists('..\packages\MSBuild.Mercurial.1.2.1\build\MSBuild.Mercurial.targets')" />
<Target Name="GetHgRev" BeforeTargets="GenerateAssemblyInfo" DependsOnTargets="PrepareForBuild">
<HgVersion LocalPath="$(SolutionDir)" Timeout="5000">
<Output TaskParameter="Revision" PropertyName="Revision" />
</HgVersion>
<Message Text="Proposed number: $(Major).$(Minor).$(Build).$(Revision)" Importance="High" />
<Message Text="AssemblyVersion before: $(AssemblyVersion)" Importance="High" />
<PropertyGroup>
<AssemblyVersion>$(Major).$(Minor).$(Build).$(Revision)</AssemblyVersion>
</PropertyGroup>
<Message Text="AssemblyVersion after: $(AssemblyVersion)" Importance="High" />
</Target>
Kind regards,Charles
工程文件的静态部分(所有在 <Target>
)在开始运行实际的构建逻辑(由target组成)之前被完全评估。
属性就像一个字符串到字符串的字典,所以 Version
和其他将被设置为字符串值,$()替换将被评估为字符串中的值,但在逻辑上不被保留。
这意味着一旦目标运行,你还需要再次更新你现在需要改变的所有属性(Version
, AssemblyVersion
, FileVersion
等)。) 您可以通过添加一个 <PropertyGroup>
后的目标内 HgVersion
任务调用。