在生成后事件中读取程序集版本号吗?

问题描述:

当我将程序集信息更改为1.0.0.1时,我以为我可以使用$(Version)读取版本,但似乎没有改变吗?

When I change the assembly information to lets say 1.0.0.1 i thought that i could read the version with $(Version) but it seems that it does not change?

您可以使用GetAssemblyIdentity任务来检索版本:

You could use the GetAssemblyIdentity task to retrieve the version :

<Target Name="AfterBuild">
  <GetAssemblyIdentity AssemblyFiles="$(OutputPath)\$(AssemblyName).$(OutputType)">
    <Output TaskParameter="Assemblies" ItemName="AssemblyIdentities"/>
  </GetAssemblyIdentity>

  <PropertyGroup>
    <CssOutputFile Condition="'$(CssOutputFile)'==''">
      ..\Styles\master-%(AssemblyIdentities.Version).css
    </CssOutputFile>
  </PropertyGroup>
  <Message Text="CssOutputFile : $(CssOutputFile)"/>
</Target>