如何动态更新Assemblyinfo.cs中的值

时间:2013-01-10 09:29:49

标签: c# wpf .net-4.0 assemblies assemblyinfo

我编写了一个从SVN存储库获取值的程序。现在我想用该值更新AssemblyFileversion。

由于我无法在Assemblyinfo.cs中编写任何代码,我将如何更新AssemblyFileVersion的值。

我想实现类似的目标

..........................
// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

 SvnInfoEventArgs info;
                    Uri repoURI = new Uri("ServerAddress");
                    svnClient.GetInfo(repoURI, out info);


[assembly: AssemblyVersion("1.0.0.0")]
    [assembly: AssemblyFileVersion(String.Format("{0}.{1}.{2}. {3}",
                                          major,minor,build,info.Revision))]

2 个答案:

答案 0 :(得分:4)

我假设您正在尝试在此处生成一些构建系统 - 基本上,您需要使用svn编号修改AssemblyInfo.cs文件。

您可以为此创建MS Build任务:请参阅http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file

命令行实用程序(SubWCRev)也可以用于基于关键字的替换($ WCREV $用于修订) - 请参阅此处的示例:http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev-example.html

最后,您可以推出自定义代码(进行正则表达式搜索/替换)以执行与某些(包括我)相同的操作 - 请参阅此处的一个示例:http://www.codeproject.com/Articles/168528/Automatically-keep-Assembly-revisions-in-sync-with

答案 1 :(得分:1)

您需要在构建过程中执行此操作。

由于您使用的是Visual Studio,因此您已使用MSBuild,在这种情况下MSBuild Extension PackAssemblyInfo任务。

为了从Subversion获取修订版,MSBuild扩展包也获得了a task for that

或者,如果您使用TeamCity进行持续集成(CI),则它具有“AssemblyInfo修补程序”构建功能。我猜大多数其他CI系统都会有类似的东西。