[英]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. 我们有一个名为
ProductVersion
的项目,其中“Product”实际上是产品名称。 Inside is a static class called VersionInformation
which contains constant strings including one called ProductVersion
, which is where we actually set the version information. Inside是一个名为
VersionInformation
的静态类,它包含常量字符串,包括一个名为ProductVersion
字符串,这是我们实际设置版本信息的地方。
Then in each project's AssemblyInfo.cs
file, our AssemblyVersion
line looks like this: 然后在每个项目的
AssemblyInfo.cs
文件中,我们的AssemblyVersion
行如下所示:
[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. 将版本信息移动到解决方案根目录中的单独文件(例如AssemblyVersion.cs)中。 Then remove the version info from each project's AssemblyInfo.cs file and add the shared AssemblyVersion file to each project as a link.
然后从每个项目的AssemblyInfo.cs文件中删除版本信息,并将共享的AssemblyVersion文件作为链接添加到每个项目中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.