动态版本控制 [英] Dynamic Versioning

查看:22
本文介绍了动态版本控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望版本控制在构建时是动态的.

I have a situation where i want the versioning to be dynamic at build time.

版本模式:...

但我已经阅读了在编译时重新解析属性中使用的字符串值的位置.

But i have read where the String value used in the Attribute is reparsed at compile time.

有关如何完成此动态版本控制的任何建议?

Any advise on how to get this dynamic versioning completed?

理想情况:

<Assembly: AssemblyVersion("4.0.0.0")> 
<Assembly: AssemblyFileVersion(Year(Now) & "." & Month(Now()) & "." & Day(Now()) & "." & String.format("hhmm", now()))> 

我知道这行不通,但应该明白这一点.

I know it wont work but should get the point acrossed.

推荐答案

您可以使用 MsbuildCommunityTasks 生成构建号并在预构建时自定义程序集文件版本.

You can use the MsbuildCommunityTasks to generate the build number and to customize the assembly file version on pre-build time.

解压到文件夹 [SolutionFolder]\MsBuildExtensions\MSBuildCommunityTasks

Unzip to the folder [SolutionFolder]\MsBuildExtensions\MSBuildCommunityTasks

在您的项目 (csproj) 中添加以下示例,就在 Microsoft.CSharp.Targets 导入之后.

Add the sample below on your project (csproj), just after the Microsoft.CSharp.Targets import.

  <PropertyGroup>
  <MSBuildCommunityTasksPath>$(MSBuildThisFileDirectory)..\MsBuildExtensions\MSBuildCommunityTasks</MSBuildCommunityTasksPath>  
    <My-PropertiesDir>Properties</My-PropertiesDir>
  </PropertyGroup>
  <Import Project="$(MSBuildCommunityTasksPath)\MSBuild.Community.Tasks.Targets"/>
  <Target Name="BeforeBuild">
    <Time Format="yyyy.MM.dd.HHmm">
      <Output TaskParameter="FormattedTime" PropertyName="My-VersionNumber" />
    </Time>
    <Message Text="Building $(My-VersionNumber) ...">
    </Message>
    <ItemGroup>
      <My-AssemblyInfo Include="$(My-PropertiesDir)\AssemblyVersionInfo.cs" />
      <Compile Include="@(My-AssemblyInfo)" />
    </ItemGroup>
    <MakeDir Directories="$(My-PropertiesDir)" />
    <AssemblyInfo OutputFile="@(My-AssemblyInfo)"
          CodeLanguage="CS"
          AssemblyFileVersion="$(My-VersionNumber)"
          AssemblyInformationalVersion="$(My-VersionNumber)"
          Condition="$(My-VersionNumber) != '' "
          />
  </Target>
  <Target Name="AfterBuild">
    <Delete Files="@(My-AssemblyInfo)" />
  </Target>

  • 从您的 AssemblyInfo.cs 中擦除 AssemblyFileVersion 属性.它将在构建时生成.

  • Wipe the AssemblyFileVersion attribute from your AssemblyInfo.cs. It will be generated at build time.

构建时,您会在控制台上看到打印的版本号.生成的文件在 AfterBuild 目标上被删除,以保持您的源代码控制干净.

You'll see the version number being printed on the console when you build. The generated file is deleted on the AfterBuild target, to keep your source control clean.

构建前:

建设 2013.01.14.1016 ...创建了 AssemblyInfo 文件Properties\AssemblyVersionInfo.cs".

Building 2013.01.14.1016 ... Created AssemblyInfo file "Properties\AssemblyVersionInfo.cs".

(...)

构建后:

正在删除文件Properties\AssemblyVersionInfo.cs".

Deleting file "Properties\AssemblyVersionInfo.cs".

如果您想对许多具有较少 msbuild 代码的项目执行此操作,则有必要创建自定义构建脚本来完成您的解决方案.

If you want do this to many projects with less msbuild code, it will be necessary to create a customized build script to wrap up your solution.

这篇关于动态版本控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆