我目前在我的应用程序的标签中包含了我发布/发布的版本号,但一直无法弄清楚如何添加它以便它在每次发布时自动更新。目前,我只使用一个简单的文本:
//VERSION LABEL
string version = "1.0.0.15 - BETA";
versionLabel.Text = "v" + version;
有没有办法在每次发布时自动更新版本?
最佳答案
使用汇编版本怎么样?这取决于您是否让它自动升级,这可以为您节省一些时间。
var appVersion = Assembly.GetExecutingAssembly().GetName().Version;
versionLabel.Text = String.Format("v{0}", appVersion);
这将基于 AssemblyInfo
的版本。
为了详细说明我的意思,如果您查看 AssemblyInfo.cs
,您会看到如下内容:
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
这实质上是说,如果您将其设为 1.0.*
或 1.0.0.*
,VS 将恭敬地为您分配修订版或构建和修订版每一次编译。
关于c# - 在标签中自动包含版本号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14616939/