简体   繁体   English

如何在Visual C#项目之间同步版本?

[英]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文件作为链接添加到每个项目中。

  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. 将生成的文件拖到每个项目中的Properties文件夹中。
  4. ??? ???
  5. Profit! 利润!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将Visual Studio默认为C#项目而不是VB.NET? - How do I default Visual Studio to C# projects instead of VB.NET? 如何在多个Visual Studio项目之间共享属性? (特别是C#项目) - How to share properties between multiple Visual Studio projects? (especially C# projects) 如何在c#中保持项目之间共享的公共代码? - How do I keep common code shared between projects in c#? 如何获得我的 C# 项目之间的依赖关系图 - How do I get a diagram of the dependencies between my C# projects 如何在C#中以编程方式确定Windows 7的子版本? - How do I determine sub versions of Windows 7 programatically in C#? 如何在C#项目中设计View逻辑 - How do I design View logic into c# projects 如何使用C#以编程方式编译项目和解决方案? - How do I programmatically compile projects and solutions in release with c#? visual c#2010在两个项目之间进行通信 - visual c# 2010 communicating between two projects 项目之间的Type.GetType()可见性问题(Visual C#) - Type.GetType() visibility issue between projects (Visual C#) 如何在C#和Wpf项目之间进行通信? - How to communicate between C# and Wpf projects?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM