Set Product Version and File Version to different numbers in C#

余生长醉 提交于 2021-02-07 20:37:39

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/60113511/set-product-version-and-file-version-to-different-numbers-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!