Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I add custom version strings to a .net DLL?

I can add custom version strings to a C++ DLL in Visual Studio by editing the .rc file by hand. For example, if I add to the VersionInfo section of the .rc file

VALUE "BuildDate", "2008/09/19 15:42:52"

Then that date is visible in the file explorer, in the DLL's properties, under the Version tab.

Can I do the same for a C# DLL? Not just for build date, but for other version information (such as source control information)

UPDATE: I think there may be a way to do this by embedding a windows resource, so I've asked how to do that.

like image 704
Simon Avatar asked Sep 23 '08 13:09

Simon


2 Answers

Expanding on the Khoth's answer, In AssemblyInfo.cs:

You can do:

[assembly: CustomResource("Build Date", "12/12/2012")]

Where CustomResource is defined as:

[AttributeUsage(AttributeTargets.Assembly)]
public class CustomResourceAttribute : Attribute
{        
    private string the_variable;
    public string Variable  {get { return the_variable; }}

    private string the_value;
    public string Value     {get { return the_value; }}

    public CustomResourceAttribute(string variable, string value)
    {
        this.the_variable = variable;
        this.the_value = value;
    }
}

This solution is nice because it gives you the flexibility you need and it does not cause any compiler warnings.

Unfortunately it is not possible to use a DateTime because the values entered in Attributes must be constants, and a DateTime is not a constant.

like image 134
KyleLanser Avatar answered Oct 18 '22 16:10

KyleLanser


In AssemblyInfo.cs, you can put:

[assembly: System.Reflection.AssemblyInformationalVersion("whatever you want")]

It's a compiler warning if it's not a number like 1.2.3.4, but I'm fairly sure everything will work.

like image 34
Khoth Avatar answered Oct 18 '22 16:10

Khoth