Reputation: 2682
I want to change the assembly version number of a C# project at build time by passing it as a property on the MSBuild command line.
AssemblyInfo Task will modify the assembly version inside a AssemblyInfo.cs before compiling. This is nearly what I want. The problem is I don't want AssemblyInfo.cs to be changed because of source control issues. I don't want all these AssemplyInfo.cs files to show as being modified and needing to be checked in every time we do a build.
What I would like is a "thing" that changes the assembly version number after compilation - perhaps using a post build weaving task. Does such a "thing" already exist somewhere either as open source or a retail product? If not, can someone point me to documentation for writing a post build weaver task?
Upvotes: 6
Views: 12726
Reputation: 22404
It might be best to have another file checked in and create an AssemblyInfo.cs from with http://code.mattgriffith.net/UpdateVersion/ or something like this from Subversion http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html
Upvotes: 0
Reputation: 3133
Since the AssemblyVersion
does get cooked into your assembly at compile time, the AssemblyInfo.cs
file with the current build number does belong in source control.
If your issue with storing this in source control is because you don't want tons of files that need to be updated, try this.
You can establish links in your solution so that all projects point to a single file, e.g. SharedAssemblyInfo.cs
. Here is a page describing this process:
You can use the SharedAssemblyInfo.cs
file using the AssemblyInfo task that you know about already, and this will be the only file that needs to be checked back into source control.
Upvotes: 7
Reputation: 5430
Try setting the AssemblyVersion in your AssemblyInfo.cs file as following:
[assembly: AssemblyVersion("1.0.*")]
It should increase your AssemblyVersion with every build, if something changed.
Upvotes: 1
Reputation: 9938
You can use the WriteCodeFragment task to generate with each build a new source file (named perhaps _AssemblyInfo.cs) that is not in source control and that contains only the AssemblyVersion attribute. Add the _AssemblyInfo.cs file to the project normally and generate it in a custom target that executes prior to the Build step. That would be less intrusive than manipulating the assembly after you've built it.
Upvotes: 3