views:

304

answers:

2

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.

+3  A: 

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.

Khoth
Thanks - that shows up as 'Product Version', which may be acceptable as a workaround. What I'd really like is to be able to see 'Build Date' show up as the name of the property.
Simon
+5  A: 

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.

KyleLanser
Still two problems:The first is that you can only add one CustomResourceAttribute that way; I think you need to add "AllowMultiple = true" to your AttributeUsage attribute there.The second is that the custom resources don't show up in the version tab - how do I get them to do that?
Simon
You are correct, I forgot the AllowMultiple. I will attempt at lunch today(thursday, -7 timezone.) to get data showing on the version tab.
KyleLanser
Sorry, no time, I'll play with it this weekend.
KyleLanser