我的 ClickOnce 发布名称与程序集名称不同。出于讨论目的,它是“App 6.0”。我在项目的属性中设置了它。有没有办法从程序内部获取这个值?
添加对
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。
答案可以在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);
}
});
ApplicationDeployment.UpdatedApplicationFullName 属性
这些答案都不适用于 .net 7。请注意