我正在使用基于ant的构建系统,并且有一个关于更新AssemblyInfo.cs的类似问题。
我的构建系统已经生成了version.h文件,这些文件在构建时包含在其他项目中。对于 C#,我决定使用生成的VersionInfo.cs将版本信息注入到AssemblyInfo.cs中。
AssemblyInfo.cs (在指定 VersionInfo 常量后设置)
using System.Reflection;
using System.Runtime.InteropServices;
[assembly: AssemblyCompany(VersionInfo.Company)]
[assembly: AssemblyProduct(VersionInfo.ProductName)]
[assembly: AssemblyCopyright(VersionInfo.Copyright)]
[assembly: Guid("12345678-1234-1234-1234-1234567890ab")]
[assembly: AssemblyVersion(VersionInfo.product.FileVersion)]
[assembly: AssemblyFileVersion(VersionInfo.sdk.FileVersion)]
VersionInfo.cs (由ant构建系统动态生成)
// Shared Product Version Header
// Automatically Generated: Sat, 2 May 2015 15:09:09 EDT
// ReSharper disable CheckNamespace
// ReSharper disable InconsistentNaming
internal struct VersionInfo
{
public const string Company = @"My Company Corp";
public const string Copyright = @"Copyright (c) 2015 My Company Corp. All rights reserved.";
public const string ProductName = @"My Software Service";
public const string SpecialBuild = @"";
public const string ProductConfiguration = @"";
public const string ProductCode = @"MSS";
public const string ProductUrl = @"www.MyCompany.com";
public const string ProductEmail = @"support@MyCompany.com";
public const string ProductVendor = @"My Company Corp";
internal struct product
{
public const string FileVersion = @"1.5.0.240";
}
internal struct sdk
{
public const string FileVersion = @"1.4.5.222";
}
internal struct service
{
public const string FileVersion = @"1.3.2.142";
}
}
version.xml (蚂蚁导入 - 剪断)
<echo file="${artifacts.dir}\VersionInfo.cs" append="false">// Shared Product Version Header${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">// Automatically Generated: ${version.generated.time}${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">// ReSharper disable CheckNamespace${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">// ReSharper disable InconsistentNaming${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">internal struct VersionInfo${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">{${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true"> public const string Company = @"${product.company}";${line.separator}</echo>
<echo file="${artifacts.dir}\VersionInfo.cs" append="true"> public const string Copyright = @"${product.copyright}";${line.separator}</echo>
<!-- other version info here -->
<echo file="${artifacts.dir}\VersionInfo.cs" append="true">}${line.separator}</echo>
version.properties (指定产品版本信息的 ant 属性文件)
product.company=My Company Corp
product.copyright=Copyright (c) 2015 My Company Corp. All rights reserved.
product.website=www.MyCompany.com
product.email=support@MyCompany.com
product.vendor=My Company Corp
product=1.5.0.240
service=1.3.2.142
sdk=1.4.5.222
C# 预构建事件 (将自动生成的 VersionInfo.cs 复制到项目属性目录)
@ECHO OFF
SETLOCAL
SET ARTDIR=$(ProjectDir)..\..\..\MySoftwareService\installer
SET VERCS=%ARTDIR%\VersionInfo.cs
ECHO Updating %VERCS%
xcopy /D /Y "%VERCS%" "$(ProjectDir)Properties"
MSBuild 扩展 (无!)
<!-- none, not required -->
顺便说一句,我的版本方案是:major.minor.revision.build 这不是 AssemblyInfo.cs 文件指定的内容。