C# 如何使安装程序的版本号与已安装程序集的版本号保持同步?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/422344/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 02:49:25  来源:igfitidea点击:

How to keep the installer's version number in sync with the installed assemblies' version numbers?

c#visual-studiodeployment

提问by Robert Rossney

In my current project, I'm producing weekly releases. I've been using the technique described in this postto keep the version numbers of all of the assemblies in my project in sync. (I don't presently have any good reason to track the assemblies' version numbers separately, though I'm sure that day will eventually come.)

在我当前的项目中,我每周发布一次。我一直在使用这篇文章中描述的技术来保持项目中所有程序集的版本号同步。(我目前没有任何充分的理由单独跟踪程序集的版本号,尽管我确信那一天最终会到来。)

When I push out a release, I build a new version of the installer. Unlike all of the assemblies, which can get their version numbers from a shared SolutionInfo.cs file, the version number of the installer isn't, as best I can tell, an assembly property. So my release process includes manually advancing the version number in the setup project.

当我推出一个版本时,我会构建一个新版本的安装程序。与可以从共享的 SolutionInfo.cs 文件中获取版本号的所有程序集不同,安装程序的版本号不是,据我所知,不是程序集属性。所以我的发布过程包括手动推进安装项目中的版本号。

Or, I should say, usuallyincludes doing that. I'd like to turn that into something I can't screw up. I'm finding the documentation of setup and deployment projects to be surprisingly opaque (it was quite a bit harder to find out how to make it possible for the MSI to uninstall properly if the user installed it to a non-default path, which is a pretty freaking common use case to be undocumented) and have no idea if it's even possible to do this.

或者,我应该说,通常包括这样做。我想把它变成我不能搞砸的东西。我发现安装和部署项目的文档令人惊讶地不透明(如果用户将 MSI 安装到非默认路径,则很难找出如何使 MSI 正确卸载,这是一个非常奇怪的常见用例没有记录)并且不知道是否有可能做到这一点。

Any ideas?

有任何想法吗?

Edit:

编辑:

Just to clarify, this is a Visual Studio setup and deployment project I'm talking about.

澄清一下,这是我正在谈论的 Visual Studio 设置和部署项目。

采纳答案by Dirk Vollmar

CodeProject has a script to set the version number of an MSI file, which you could run in the pre-built step of the setup project. You find it here:

CodeProject 有一个脚本来设置 MSI 文件的版本号,您可以在安装项目的预构建步骤中运行该脚本。你可以在这里找到它:

http://www.codeproject.com/KB/install/NewSetupVersion.aspx

http://www.codeproject.com/KB/install/NewSetupVersion.aspx

More Details

更多细节

Be aware that with Windows Installer things are a bit more complicated. MSI files (as the one that you create using a VS Setup and Deployment project) not only have a version number but also a product code which is a GUID value. This product code is used by Windows Installer to uniquely identify your product e.g. in Control Panel -> Add Or Remove programs where you can decide to uninstall or repair a product.

请注意,使用 Windows Installer 时事情会复杂一些。MSI 文件(作为您使用 VS 安装和部署项目创建的文件)不仅具有版本号,还具有作为 GUID 值的产品代码。Windows Installer 使用此产品代码来唯一标识您的产品,例如在控制面板 -> 添加或删除程序中,您可以在其中决定卸载或修复产品。

However, when changing you MSI version number, this product code must also be changed in a number of cases. MSI technology is poorly documented but you can find some recommendations when to also change the product code on the following MSDN page: http://msdn.microsoft.com/en-us/library/aa367850(VS.85).aspx.

但是,在更改 MSI 版本号时,在许多情况下也必须更改此产品代码。MSI 技术的文档很少,但您可以在以下 MSDN 页面上找到一些何时更改产品代码的建议:http: //msdn.microsoft.com/en-us/library/aa367850(VS.85).aspx

In my projects I always generate a new product code for every new version. The script on CodeProject will also change the product code for you.

在我的项目中,我总是为每个新版本生成一个新的产品代码。CodeProject 上的脚本也会为您更改产品代码。

And one more thing: Windows Installer only checks the first three places of the version number afaik, anything in the forth place will be ignored, i.e. 2.3.0.1234 is considered equal to 2.3.0.5678. (ProductVersion)

还有一件事:Windows Installer 只检查版本号 afaik 的前三位,第四位的任何内容都将被忽略,即 2.3.0.1234 被认为等于 2.3.0.5678。(的ProductVersion

(There is a related article on CodeProject which might also be interesting to you: http://www.codeproject.com/KB/install/VersionVDProj.aspx)

(有一篇关于 CodeProject 的相关文章,您可能也会感兴趣:http: //www.codeproject.com/KB/install/VersionVDProj.aspx

回答by Rob McCready

Its going to depend on the installer toolkit you are using.

它取决于您使用的安装程序工具包。

We use TFS Team Build and WiX v3. I have a custom build task that increments the build number in Team build (5.0.0.X for example), then this version number is pushed to the common AssemblyInfo.cs AssemblyFileVersion field. It is also passed by MSBuild to our solutions/projects as a property which is then passed into WiX and used to update the installer version as well.

我们使用 TFS Team Build 和WiX v3。我有一个自定义构建任务,它增加团队构建中的构建号(例如 5.0.0.X),然后将此版本号推送到常见的 AssemblyInfo.cs AssemblyFileVersion 字段。它也由 MSBuild 作为属性传递给我们的解决方案/项目,然后传递给 WiX 并用于更新安装程序版本。

We probably will need to do better with the assembly versioning someday as well, but right now this has been working pretty well for us.

我们可能有一天也需要在程序集版本控制方面做得更好,但现在这对我们来说效果很好。

回答by Philip Marks

I use a workaround for VS2010 Setup projects (.MSI + setup.exe). Open the .vdproj in Notepad and edit the ProductVersion assignment value (3.2.1 in the example below). Save the file and launch VS2010 by double-clicking on the .vdproj file.

我对 VS2010 安装项目 (.MSI + setup.exe) 使用了一种解决方法。在记事本中打开 .vdproj 并编辑 ProductVersion 分配值(在下面的示例中为 3.2.1)。保存文件并双击 .vdproj 文件启动 VS2010。

    "Product"
    {
    "Name" = "8:Microsoft Visual Studio"
    "ProductName" = "..."
...
    "ProductVersion" = "8:3.2.1"
    "Manufacturer" = "..."
...
    }