我如何在.NET应用程序目前公布的版本? [英] How do I get the current published version in a .NET application?
问题描述
我希望能够以显示我已经使用发布向导部署.NET应用程序的当前版本。有是一个不错的选择每次发布我的应用程序时,自动更新的版本号
I want to be able to display the current version of a .NET application that I have deployed using the publish wizard. There is a nice option to automatically update the version number every time I publish my application.
我发现了一个问题(的的Automatically更新版本号 的那个是这样获得最新的版本):
I found another question (Automatically update version number) that had this to get the current version:
Assembly.GetExecutingAssembly().GetName().Version
这让你在项目属性中设置的版本,但不是在每次发布时自动递增的版本。
This gets you the version you set in the project properties, but not the version that is automatically incremented each time you publish.
推荐答案
我最终使用的代码,这一点得到当前部署的版本,或者如果它没有部署当前的程序集版本。
I ended up using this little bit of code to get the current deployed version or if it isn't deployed the current assembly version.
private Version GetRunningVersion()
{
try
{
return Application.ApplicationDeployment.CurrentDeployment.CurrentVersion;
}
catch
{
return Assembly.GetExecutingAssembly().GetName().Version;
}
}
我不得不引用添加到 System.Deployment
和的System.Reflection
。
这篇关于我如何在.NET应用程序目前公布的版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!