简体   繁体   English

有没有一种方法可以解析应用程序清单?

[英]Is there a way to parse a application manifest?

I am looking for a way to have the hosting website parse out the [appname].manifest file to pull out the application name, version, and icon if available. 我正在寻找一种让托管网站解析[appname] .manifest文件以提取应用程序名称,版本和图标(如果可用)的方法。 This way I can put it into a control for easy deployment. 这样,我可以将其放入控件中以方便部署。 Are there any framework calls that will assist me in parsing out the manifest file? 是否有任何框架调用可以帮助我解析清单文件?

The files I am looking for are [appname].application and/or [appname].manifest 我要查找的文件是[appname] .application和/或[appname] .manifest

System.Diagnostics.FileVersionInfo will do most of the heavy lifting for you. System.Diagnostics.FileVersionInfo将为您完成大部分繁重的工作。 It'll extract meta-data from a file to determine the assembly's Product Name & Version. 它将从文件中提取元数据,以确定程序集的产品名称和版本。 As for the Icon, that's a different story, but at least this is a start for you: 至于图标,那是一个不同的故事,但至少这是您的起点:

Update: 更新:

Also using System.Reflection.Assembly you can call GetManifestResourceInfo(string) , GetManifestResourceNames() , and GetManifestResourceStream(string) to access an assembly's resources (for the Icon). 同样使用System.Reflection.Assembly,您可以调用GetManifestResourceInfo(string)GetManifestResourceNames()GetManifestResourceStream(string)来访问程序集的资源(用于Icon)。

You can get most of the info you want using the System.Deployment.Application.InPlaceHostingManager class - don't be fooled by the name, it is primarily for browser-hosted ClickOnce apps, but also works for standalone ClickOnce apps. 您可以使用System.Deployment.Application.InPlaceHostingManager类获取所需的大多数信息-不要被名称所迷惑,它主要用于浏览器托管的ClickOnce应用程序,但也适用于独立的ClickOnce应用程序。 Once you initialise an instance and pass it the URL to the .application file, you can call GetManifestAsync() - in the event handler for GetManifestCompleted , you can get the application name and version: 初始化实例并将URL传递给.application文件后,您可以调用GetManifestAsync() -在GetManifestCompleted的事件处理程序中,您可以获取应用程序的名称和版本:

void iphm_GetManifestCompleted(object sender, GetManifestCompletedEventArgs e) {
    Console.WriteLine("Application name: {0}", e.ApplicationIdentity);
    Console.WriteLine("Application version: {0}", e.Version);
}

The icon is usually referenced in the application manifest (.application is the deployment manifest) - the app manifest can be accessed using InPlaceHostingManager ; 该图标通常在应用程序清单中引用(.application是部署清单)-可以使用InPlaceHostingManager访问该应用程序清单; in the above example, you'd get the value from e.ApplicationManifest which would give you an XmlReader to play with. 在上面的示例中,您将从e.ApplicationManifest获取值,这将为您提供一个XmlReader来使用。

Probably best to study the relevant XML schema(s) and then find the icon using XQuery. 最好研究相关的XML模式,然后使用XQuery查找图标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM