How to update the Value in Assemblyinfo.cs dynamically

Simsons picture Simsons · Jan 10, 2013 · Viewed 23.8k times · Source

I have writen a program which gets the value from SVN repository . Now I want to update the AssemblyFileversion with that value.

As I am not able to write any code inside Assemblyinfo.cs , how will I update the value of AssemblyFileVersion.

I want to achieve something like this

..........................
// 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))]

Answer

VinayC picture VinayC · Jan 10, 2013

I am assuming that you are trying to generate some build system here - so essentially, you need to modify AssemblyInfo.cs file with svn number.

You can create MS Build task for the same: see http://florent.clairambault.fr/insert-svn-version-and-build-number-in-your-c-assemblyinfo-file

There is command line utility (SubWCRev) that can also be used for keyword based replacement ($WCREV$ for revision) - see the example here: http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev-example.html

Finally, you can probably roll out your custom code (doing regex search/replace) to do the same which some (including me) has done - see one such example here: http://www.codeproject.com/Articles/168528/Automatically-keep-Assembly-revisions-in-sync-with.