c# - 程序集命名和版本控制的最佳实践?

标签 c# .net assemblies versioning

我正在寻找一些关于命名程序集和对其进行版本控制的良好做法。您多久增加一次主要或次要版本?

在某些情况下,我看到版本从 1.0 直接升级到 3.0。其他情况好像卡在1.0.2.xxxx版本。

这将用于整个公司的多个项目中使用的共享程序集。期待一些好的输入。

最佳答案

来自 this article 的一些有用信息在 Suzanne Cook 的 MSDN 博客上(发布于 2003-05-30):

When to Change File/Assembly Versions

First of all, file versions and assembly versions need not coincide with each other. I recommend that file versions change with each build. But, don’t change assembly versions with each build just so that you can tell the difference between two versions of the same file; use the file version for that. Deciding when to change assembly versions takes some discussion of the types of builds to consider: shipping and non-shipping.

Non-Shipping Builds
In general, I recommend keeping non-shipping assembly versions the same between shipping builds. This avoids strongly-named assembly loading problems due to version mismatches. Some people prefer using publisher policy to redirect new assembly versions for each build. I recommend against that for non-shipping builds, however: it doesn’t avoid all of the loading problems. For example, if a partner x-copies your app, they may not know to install publisher policy. Then, your app will be broken for them, even though it works just fine on your machine.

But, if there are cases where different applications on the same machine need to bind to different versions of your assembly, I recommend giving those builds different assembly versions so that the correct one for each app can be used without having to use LoadFrom/etc.

Shipping Builds
As for whether it’s a good idea to change that version for shipping builds, it depends on how you want the binding to work for end-users. Do you want these builds to be side-by-side or in-place? Are there many changes between the two builds? Are they going to break some customers? Do you care that it breaks them (or do you want to force users to use your important updates)? If yes, you should consider incrementing the assembly version. But, then again, consider that doing that too many times can litter the user’s disk with outdated assemblies.

When You Change Your Assembly Versions
To change hardcoded versions to the new one, I recommend setting a variable to the version in a header file and replacing the hardcoding in sources with the variable. Then, run a pre-processor during the build to put in the correct version. I recommend changing versions right after shipping, not right before, so that there's more time to catch bugs due to the change.

关于c# - 程序集命名和版本控制的最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/199823/

相关文章:

c# - 使用适用于 .NET 的 AWS S3 SDK 从 Amazon S3 下载并行批处理文件

c# - 部署 NetFwTypeLib 以管理 Windows 防火墙

c# - 找不到适合指定区域性的任何资源

assemblies - 将程序集添加到 Visual Studio 2015 ASP.NET 5

c# - 在 C# 上解析 Delphi 项目文件

c# - 代理在本地工作,但在上传到 webhost 时失败

c# - Math.Sqrt() 的时间复杂度?

c# - 卸载使用 DllImport 加载的 DLL

.net - 我的程序保留使用 GDI+ 编写的文件

.net - 编译时引用.NET dll(单声道)