9

我很难在我的程序集/exe 中获取版本信息。似乎有很多关于此的问题,但没有一个可以帮助我解决问题。

能够在我的exe中包含版本信息似乎是基本和简单的,但是当我从资源管理器中查看上下文菜单时它没有显示(右键单击->属性->详细信息)

如何将版本信息(不使用插件)添加到我的 C# 紧凑框架/WinMobile 6.0 项目中?

这是默认的 assemblyinfo.cs

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following 
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TestingVerInfo")]
[assembly: AssemblyDescription("hello")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("world")]
[assembly: AssemblyProduct("TestingVerInfo")]
[assembly: AssemblyCopyright("Copyright ©  2011")]
[assembly: AssemblyTrademark("gggg")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible 
// to COM components.  If you need to access a type in this assembly from 
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5e5fffea-0c9d-4394-9a0f-d24b7e7db9ed")]

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
[assembly: AssemblyVersion("1.0.0.0")]

这是不太令人印象深刻的文件详细信息:

在此处输入图像描述

4

2 回答 2

6

也许我不明白这个问题,但包含版本信息就像设置assembly: [AssemblyVersion][1]属性一样简单。您可以使用以下方式查询它:

 var version = Assembly.GetExecutingAssembly().GetName().Version;

更新

好吧,这是一个非常奇怪的行为。我知道我的应用程序和程序集中有版本信息,所以我打开了 Studio 并创建了一个新的智能设备项目并保留了所有默认值。果然,我得到了你看到的行为——也就是说没有版本信息。怎么回事?我回去打开了一个存根项目,它确实在二进制文件中有版本信息,AssemblyInfo.cs文件真的没有什么不同。

我玩了一下,结果发现如果您将项目的目标平台从“Windows Mobile Xxxx”更改为“Windows CE”(如果这样做,您仍然可以部署到 WinMo 目标),那么版本信息结束在二进制文件中。不知道为什么会出现这种情况 - WinMo 配置的编译器命令行必须与 CE 配置不同。

于 2011-10-25T16:51:09.217 回答
1

为 Windows Mobile 生成的应用程序不是使用标准的 Windows 操作系统可执行格式创建的。这意味着您正在运行的 Windows 操作系统不知道如何从文件中提取信息以填充详细信息选项卡。

话虽如此,版本信息仍然嵌入在应用程序中,并且可以在移动设备上使用。如果您需要在应用程序中向用户显示此信息(例如,关于框),可以使用包括 GetFileVersionInfo 和 VerQueryValue 在内的 coredll 方法来检索此数据。

我们检索这些数据的类大约有 350 行长,所以我认为在这里发帖不合适,而且我无法快速找到我们获得原始想法的来源。如果需要,我可以对此进行更多研究。

于 2011-10-31T01:52:32.913 回答