English 中文(简体)
如何使 C# .NET CF 程序的 AssemblyInfo 版本传播到资源管理器属性窗口?
原标题:
  • 时间:2008-09-24 12:50:41
  •  标签:

似乎如果您在AssemblyInfo.cs文件中编译Visual Studio解决方案并有一个版本#,那么应该传播到例如Windows资源管理器属性对话框。这样,有人可以简单地右键单击*.exe并单击属性来查看版本#。在Visual Studio中是否有特殊设置可以使此操作发生?

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?

问题回答

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

See this article from Daniel Mooth for a workaround.

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();
    }
}

You need to add another attribute:

[assembly: AssemblyFileVersion("1.0.114.0")]

Note that you still need the AssemblyVerison one as well to correctly identify the assembly to the .NET runtime.

版本号会传播到属性对话框中的“版本”选项卡,但不会传播到摘要中。不幸的是,由于信息是附加到文件本身的元数据,因此VS不会自动填充文件的摘要信息。但是,您可以通过使用来自Microsoft的免费DSO OleDocument属性阅读器来访问和操作摘要信息。

You can acquire the library from: http://www.microsoft.com/downloads/details.aspx?FamilyId=9BA6FAC6-520B-4A0A-878A-53EC8300C4C2&displaylang=en

Further information on its use can be found at: http://www.developerfusion.co.uk/show/5093/

EDIT: As noted above by pb and Nigel Hawkins you can get the property to propogate by using the AssemblyFileVersion attribute like:

[assembly: AssemblyFileVersion("1.0.114.0")]

I m not sure that RevisionNumber is the correct field to be looking for.

Try explorer, right click -> version tab, and look at the AssemblyVersion field there.

in my project we use FileVersion = YYYY.MM.DD.BUILD (e.g., 2008.9.24.1) but the ProductVersion should be major.minor.revision.BUILD. we use the AssemblyInformationalVersion to get around this.

AssemblyVersion="MAJ.MIN.REV.1" --> used by .NET

AssemblyInformationalVersion="MAJ.MIN.REV.XXX" --> used in explorer s ProductVersion

AssemblyFileVersion="YYYY.MM.DD.XXX" --> used in explorer s FileVersion





相关问题
热门标签