在 C# 中将产品版本和文件版本设置为不同的数字 [英] Set Product Version and File Version to different numbers in C#

查看:37
本文介绍了在 C# 中将产品版本和文件版本设置为不同的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 C++ 项目中,我可以使用

我在 C# 项目中无法实现相同的目标.我在 AssemblyInfo.cs 文件中设置了以下内容:

[程序集:AssemblyVersion("1.0")][程序集:AssemblyFileVersion("1.0.0.1")]

但是,在 DLL 属性中,两者都设置为 File Version 的值:

如何在 C# DLL 中将产品版本和文件版本设置为不同的值?我使用的是 Visual Studio 2019.

解决方案

您可以使用 AssemblyInformationalVersion 属性设置产品版本"信息中显示的值.在您的 Assembly.cs 文件中像这样设置:

[程序集:AssemblyInformationalVersion("1.2.3.4")]

来自 Microsoft 文档:

<块引用>

注意:如果 AssemblyInformationalVersionAttribute 属性不是应用于程序集,由指定的版本号AssemblyVersionAttribute 属性由Application.ProductVersion、Application.UserAppDataPath 和Application.UserAppDataRegistry 属性.

In a C++ project, I can add different Product Version and File Version values to my assembly using VERSIONINFO in a Version resource file:

#define VER_PRODUCTVERSION          1,0,0,0
#define VER_PRODUCTVERSION_STR      "1.0\0"

#define VER_FILEVERSION             1,0,0,1
#define VER_FILEVERSION_STR         "1.0.0.1\0"

This appears in the DLL properties as:

I'm having trouble achieving the same in a C# project. I've set the following in the AssemblyInfo.cs file:

[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.0.1")]

However, in the DLL properties, both are set to the value of File Version:

How can I set Product Version and File Version to different values in a C# DLL? I'm using Visual Studio 2019.

解决方案

You can set the value displayed in the "Product Version" info using the AssemblyInformationalVersion attribute. Set this in your Assembly.cs file like this:

[assembly: AssemblyInformationalVersion("1.2.3.4")]

From the Microsoft documentation:

Note: If the AssemblyInformationalVersionAttribute attribute is not applied to an assembly, the version number specified by the AssemblyVersionAttribute attribute is used by the Application.ProductVersion, Application.UserAppDataPath, and Application.UserAppDataRegistry properties.

这篇关于在 C# 中将产品版本和文件版本设置为不同的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆