Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I sync versions between Visual C# projects?

I have three projects in my solution: a base project, and a client and server that reference the base.

What I'd like to do is be able to set the base project file's assembly version, and have that automatically propagate to the server and client so their versions always match. Ideally, this would be a pre-build step to sync them.

Does anyone know if this is possible or how I'd go about doing so?

like image 542
Louis Ingenthron Avatar asked Apr 09 '13 15:04

Louis Ingenthron


2 Answers

What we do is very similar to Chris' answer:

We have a project called ProductVersion, where "Product" is actually the product name. Inside is a static class called VersionInformation which contains constant strings including one called ProductVersion, which is where we actually set the version information.

Then in each project's AssemblyInfo.cs file, our AssemblyVersion line looks like this:

[assembly: AssemblyVersion(Company.Product.VersionInformation.ProductVersion)]

In your case, since both the client and server reference the base project, you could just include something similar in the base project instead of creating a separate project.

like image 186
Joel Rondeau Avatar answered Sep 22 '22 14:09

Joel Rondeau


Move the version info into a separate file (e.g. AssemblyVersion.cs) in your solution's root directory. Then remove the version info from each project's AssemblyInfo.cs file and add the shared AssemblyVersion file to each project as a link.

  1. Right click the project, click Add Existing Item
  2. Browse to the shared file, click the little arrow on the add button and select Add As Link
  3. Drag the resulting file to the Properties folder within each project.
  4. ???
  5. Profit!
like image 42
Chris Avatar answered Sep 19 '22 14:09

Chris