Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the AssemblyInfo version of a C# .NET CF program propagate to the Explorer Properties window?

It seems like if you compile a Visual Studio solution and have a version # in your AssemblyInfo.cs file, that should propagate to say, the Windows Explorer properties dialog. This way, someone could simply right click on the *.exe and click 'properties' to see the version #. Is there a special setting in Visual Studio to make this happen?

example picture http://content.screencast.com/users/Pincas/folders/Jing/media/40442efd-6d74-4d8a-8e77-c1e725e6c150/2008-09-24_0849.png

Edit: I should have mentioned that this is, specifically, for .NET Compact Framework 2.0, which doesn't support AssemblyFileVersion. Is all hope lost?

like image 689
Pandincus Avatar asked Dec 22 '22 14:12

Pandincus


2 Answers

Note, that the AssemblyFileVersion attribute is not available under .NET Compact Framework!

See this article from Daniel Mooth for a workaround.

like image 64
Jan Avatar answered Dec 28 '22 07:12

Jan


NOTE: This answer is for accessing the AssemblyInfo properties within a .NET CF 3.5 application. It does not propagate to the executable's "Properties" inside of Windows Explorer (but could be used to write to a file, to the console, or to display in the application)

I know this is a very old question, but here is a solution I found using Reflection and Linq to get the "AssemblyInformationalVersion" (product version in newer Visual Studio projects).

First, I added this to the AssemblyInfo.cs (replace the string with whatever you want to use):

[assembly: AssemblyInformationalVersion("1.0.0.0 Alpha")]

Then, you can use this method to pull out the attribute (I placed it inside a static class in the AssemblyInfo.cs file). The method get's an array of all Assembly attributes, then selects the first result matching the attribute name (and casts it to the proper type). The InformationalVersion string can then be accessed.

//using System.Reflection;
//using System.Linq;
public static string AssemblyInformationalVersion
{
    get
    {
        AssemblyInformationalVersionAttribute informationalVersion = (AssemblyInformationalVersionAttribute) 
            (AssemblyInformationalVersionAttribute.GetCustomAttributes(Assembly.GetExecutingAssembly())).Where( 
                at => at.GetType().Name == "AssemblyInformationalVersionAttribute").First();

        return informationalVersion.InformationalVersion;
    }
}

To get the normal "AssemblyVersion" attribute I used:

//using System.Reflection;
public static string AssemblyVersion
{
    get
    {
        return Assembly.GetExecutingAssembly().GetName().Version.ToString();
    }
}
like image 40
jarmst Avatar answered Dec 28 '22 07:12

jarmst