简体   繁体   中英

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?

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.

Move the version info into a separate file (eg 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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM