Click here to Skip to main content
15,866,422 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Target: Apply an assembly file version number over multiple projects.

For example, I have 10 projects. Each project has Property=> AssemblyInfo.cs file. There you will have AssemblyFileVersion tag as well like below.

[assembly: AssemblyFileVersion("1.0.0.0")]

I am using AssemblyInfo.tt file through which I want to apply Fileversion number. Hence I removed Fileversion from AssemblyInfo.cs file and created a AssemblyInfo.tt file where I mentioned the Fileversion and added it as a link. Yes it is applied to the project and I can see the updated file version in that project.

Now as I have 10 projects, for each project I need to do the same above operation so that it will apply the actual file version which I gave through .tt file.

This process is tedious where I have more than 100 projects in solution and I need to apply a customized file version for each.

The target is for first time I will add .tt file into all 100 projects which will be
in a central position[Upper/parent folder of the projects] and later if I change the .tt file with a new build and revision number it should automatically apply over all projects.

For reference you can look into the below links:
http://stackoverflow.com/questions/826777/how-to-have-an-auto-incrementing-version-number-visual-studio

http://vagif.bloggingabout.net/2010/04/24/using-t4-templates-to-manage-assembly-version-information/


https://msdn.microsoft.com/en-us/library/dd820620.aspx[^]

Understand the situation, If you need any additional information please let me know but don't share some link which are just meaningless examples.

Thanks in advance!!
Posted
Updated 1-Jul-15 20:59pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Jul-15 3:29am    
I voted 5 for this question. The problem is important enough, and your requirements are very reasonable.
If you auto-increment just the least significant number of the version, it can be used, but it does not solve the problem of controlled versioning of all the assemblies in sync. I solved these problems, so I can advise what to do.
—SA
Pradip Kumar Sen 2-Jul-15 3:38am    
Thank you Sir!!

Please see my comment to the question. This is a valid question.

There is no a predefined way of control the version in all project in sync, but what you want would be a very reasonable feature you may want to develop yourself. I used at least two slightly different approaches.

First, you can write a small text utility scanning the project file (it would be reasonable to limit such attribute use by the files named "Properties/AssemblyInfo") and changing the version in these files.

Another approach is to do the same in a special MSBuild Task, which can be yet another project in your solution. When you do it according to the MSBuild standard, you can use this task in one or more of your projects. It can be a project devoted specially for the task of modifying version information of all other projects when it is build. For example, it can read version from a project's Property value, or from some text file uses as a source file, finds all files to be modifies and modifies them. Alternatively, such task can be included in a project doing something else, and the version modification can be done either always (when version is modified), or only for one special Target added for this purpose. This approach will need more time, but it could streamline your development versioning. You will need to learn custom MSBuild use and related concepts. Please see:
https://msdn.microsoft.com/en-us/library/ms171466.aspx[^],
https://msdn.microsoft.com/en-us/library/ms171458.aspx[^],
https://msdn.microsoft.com/en-us/library/dd637714.aspx[^],
https://msdn.microsoft.com/en-us/library/dd393574.aspx[^].

—SA
 
Share this answer
 
v3
Comments
Pradip Kumar Sen 2-Jul-15 3:41am    
I can go with the first approach you suggested. But needs a headsup on how shall I start this scanning project. Any reference or link would do. Thanks
Sergey Alexandrovich Kryukov 2-Jul-15 9:26am    
Yes, you can. But this is trivial enough. Unlike second approach, where you can get project's properties, you have to assume that all projects files are under some root directory (say, solution's directory). Get all files using System.IO.Directory.GetFiles with the mask taking only AssemblyInfo.cs. For each such file, System.IO.File.ReadAllLines. For each line, detect version line, replace it with the version you want, use File.WriteAllLines. Something like that.

If something is unclear, feel free to ask more. If it's clear, please accept the answer formally.

—SA
Pradip Kumar Sen 3-Jul-15 5:17am    
Thank you. I got that. But due to time constraints I may not be able to experiment this now. Probably sometime later I will do. Thanks.
Sergey Alexandrovich Kryukov 3-Jul-15 12:05pm    
Sure. You are welcome. Again, what you requested makes a lot of sense.
Good luck, call again.
—SA
When I want to do that, I usually create a GlobalAssemblyInfo.cs file in a solution folder, in which I set the AssemblyVersion and/or AssemblyFileVersion attribute(s).

Then, for each project, I add this file as an already existing file, with the option of linking it instead of copying it.

Then, I make sure that, for each AssemblyInfo.cs file in each project, I delete the attributes that are set in the GlobalAssemblyInfo.cs file.

I hope I was clear enough. Please let me know if you need some more explanations.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900