Such approach to version policy management makes it impossible for wrong assembly version to be accepted by its client. It is safer to deny execution of potentially incompatible code than to believe that a different version of the component will work.
Visual Studio. NET follows this approach, and unless exact static assembly version is assigned to a component, the new version will be generated for each build.
This is achieved by placing the following version string in one of the assembly source files:. Asterisk sign instructs Visual Studio to assign on each build a version 1. Well, this is a most reasonable default behavior, but in some cases, it can be inconvenient to handle. When the number of projects grows, they will most likely be split into multiple solutions, with some of the projects contained in several solutions. So, if you have two applications, A and B, and both of them use a strong-named assembly C with utility code, you will have the following project structure:.
As long as you deploy them in different folders, everything will be fine. But if you package applications A and B to be deployed in the same folder, then one of the copies of C will be overwritten, which will prevent its corresponding application to run. Of course, this situation can be handled by version policy files, but it is the same version of the class library source code that is used to compile solutions A and B, it was just compiled twice in different solutions.
Just replace wild card with exact build and revision number, for example 1. Well, yes and no. Sure, it will resolve versioning problem, but leaves a risk for a simple human mistake: what if I update assembly source code and forget to assign a new version number? Then I will have different assemblies with the same version numbers assigned. So, which version update scheme will fit best in a development team with large number of projects combined in multiple solutions?
In our team, we run daily builds, so we decided that major and minor versions are always managed manually not an unreasonable decision , and build number should be managed automatically and assigned to the day count this is what Visual Studio does with wild card. However, to avoid incompatibility problem described in a previous section, revision number is fixed and set to 0 can be set to any other number if needed.
So, our scheme is actually maj. The only problem is that such a scheme is not supported by. We needed an external tool. Although it was tempting to write our own utility, a quick search in Google referred us to an excellent.
NET regular expression classes. UpdateVersion supports variety of schemes, and you will certainly find the one that fits your team.
And if not? Well, add your own — it comes with source code and gives you right to modify it as long as you accept its license terms. UpdateVersion and its source can be downloaded here. To apply our version update pattern maj. This will guarantee that all assemblies built during the daily build will have the same build. Next step is to embed UpdateVersion invocation into the. NET project the version of which needs to be handled this way. This is achieved by adding Pre-built event to the project properties.
Type the following text in Pre-build Event Command Line text box:. Of course, UpdateVersion. It would be too easy if the previous step was sufficient in most cases. Then you are like me, and we need to extend our build script to check out AssemblyInfo. Command ss CP… selects current SourceSafe project. Command ss checkout… checks the specified file from current SourceSafe project and copies it to the current directory.
Finally, after the file is updated, command ss checkin… checks the file in. Option -G. Yes, this can be rather irritating. I can compile some of my projects hundred times a day, and the fact that now each compilation will invoke SourceSafe does not make me happy.
I would accept it if the actual version was different, but it changes only once a day. We need to optimize this step. And it can be done very simple. Built-in Windows command-line utility fc File Compare returns different values depending on the result of file comparison. If it does not encounter any differences, it returns 0 , but if the files are different, it returns 1. As you can see, the Pre-build script is now more complex and it includes conditional statements.
Newly generated AssemblyInfo. However, if files are different which means that assembly was not compiled today , it proceeds with check-out followed by file update and check-in. The demonstrated technique will not always fit in your development environment. Perhaps, the way you assign versions to assemblies is different, or your source control management is different.
However, the idea of this article was to demonstrate that with minimal changes and no changes to your source code , you can easily customize version assignment policy to avoid manual intervention to build and deployment processes. This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
Sign in Email. Forgot your password? Write String. Delete fileName ; File. WriteLine " Done! Parse i. Join ". Ex: [assembly: AssemblyVersion "1.
Re: Just an improvement BostjanSkok 6-Nov C Copy Code using System; using System. Linq; using System. Re: Just an improvement Sergiy Korzh 6-Nov Thank you. My vote of 5 DeadlyEmbrace 2-Sep The simplest method to update the build number I have found so far! Thank you very much, this is an excellent solution. My Vote of 5 Member 7-Aug Member Thanks, works great. My vote of 5 rickist Nov Works just fine. If you use Post-build event, the updated version will only be used on the next build before being incremented again , but you can set it to increment ONLY on successfull builds and thus avoid unnecessary version increments.
Thank you for sharing mikeperetz Mar Thank you for sharing, I think this is very good and also validates my approach which is similar to yours. I was looking for a way to do this in power shell, so if you find something please post it. This must be a common problem and I think it's incredible that Visual Studio has no support for this out of the box. Thanks a lot Sudarsan Srinivasan Apr Sudarsan Srinivasan.
Thanks a lot for your tool. This has saved quite a lot of time for me!! Works like a gem! My vote of 5 lparkd 4-Oct Thx, worked very well for me Cheers. Works great for me Michael Elly Aug Thanks, I was just going to write such a utilty and I can gain from your work My vote of 5 Michael Elly Aug Try using regular expressions to parse mekansm Jan Try using Regex to parse the lines, might be a bit easier to read.
Something like this Groups[ " Major" ]. Groups[ " Minor" ]. Groups[ " Build" ]. Groups[ " Revision" ]. Synchronize version number across assemblies Marc Scheuner Jan I've been using the same method for several years now and it works great! Reflection; [assembly: System. AssemblyCompanyAttribute " AssemblyCopyrightAttribute " AssemblyDescriptionAttribute " AssemblyFileVersionAttribute " AssemblyInformationalVersionAttribute " AssemblyProductAttribute " AssemblyTitleAttribute " AssemblyVersionAttribute "1.
Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually.
0コメント