Paul
Paul

Reputation: 3954

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

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:

cpp-details

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:

cs-details

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

Upvotes: 8

Views: 13008

Answers (2)

GBute
GBute

Reputation: 31

When I edited my AssemblyInfo.cs files, and rebuilt, found that some of the values I'd just changed would get reset.

The soln was to edit the csproj file, and that took care of it!

Upvotes: 1

Adrian Mole
Adrian Mole

Reputation: 51825

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.

Upvotes: 11

Related Questions