我有一个与程序集名称不同的ClickOnce发布名称。出于讨论目的,它是“App 6.0”。我在我的项目的属性中设置它。有没有办法从程序中获取这个值?
答案 0 :(得分:3)
添加对Microsoft.Build.Tasks.v4.0.dll
的引用,然后运行:
if (null != AppDomain.CurrentDomain.ActivationContext)
{
DeployManifest manifest;
using (MemoryStream stream = new MemoryStream(AppDomain.CurrentDomain.ActivationContext.DeploymentManifestBytes))
{
manifest = (DeployManifest)ManifestReader.ReadManifest("Deployment", stream, true);
}
// manifest.Product has the name you want
}
else
{
// not deployed
}
DeployManifest还可以提供清单中的其他有用信息,例如Publisher或SupportUrl。
答案 1 :(得分:2)
ApplicationDeployment.UpdatedApplicationFullName属性
答案 2 :(得分:2)
答案可以在 ClickOnce Run at Startup 中找到。基本上,您使用InPlaceHostingManager获取ClickOnce清单并阅读它。它让我觉得它是一个异步方法,但这是迄今为止唯一有效的方法。非常感谢简化。有关DeploymentDescription的说明,请参阅网页。
var inPlaceHostingManager = new InPlaceHostingManager(ApplicationDeployment.CurrentDeployment.UpdateLocation, false);
inPlaceHostingManager.GetManifestCompleted += ((sender, e) =>
{
try
{
var deploymentDescription = new DeploymentDescription(e.DeploymentManifest);
string productName = deploymentDescription.Product;
***DoSomethingToYour(productName);***
// - use this later -
//var commandBuilder = new StartMenuCommandBuilder(deploymentDescription);
//string startMenuCommand = commandBuilder.Command;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message + Environment.NewLine + ex.StackTrace);
}
});