如何将程序集版本号(我设置为自动增量)插入Winform表单文本?
答案 0 :(得分:72)
其中任何一个都可行:
var version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
this.Text = String.Format("My Application Version {0}", version);
string version = System.Windows.Forms.Application.ProductVersion;
this.Text = String.Format("My Application Version {0}", version);
假设这是在Form
上运行,您希望在
答案 1 :(得分:13)
Text = Application.ProductVersion
快速获取字符串的完整版本(例如" 1.2.3.4")
答案 2 :(得分:9)
我在WinForm中使用以下内容:
public MainForm()
{
InitializeComponent();
Version version = Assembly.GetExecutingAssembly().GetName().Version;
Text = Text + " " + version.Major + "." + version.Minor + " (build " + version.Build + ")"; //change form title
}
未向用户显示修订号,内部版本号是足够的技术信息
确保您的AssemblyInfo.cs在以下内容中结束(默认情况下删除它所具有的版本),以便VisualStudio自动增加构建和修订号。您必须在每个版本自己更新主要版本和次要版本(更新新功能的主要版本,修复时的次要版本):
// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.*")]
答案 3 :(得分:3)
它在System.Reflection.AssemblyName
类中,例如
Assembly.GetExecutingAssembly().GetName().Version.ToString()
答案 4 :(得分:2)
正如您在此处所见:http://msdn.microsoft.com/en-us/library/system.reflection.assemblyname.version.aspx
class Example
{
static void Main()
{
Console.WriteLine("The version of the currently executing assembly is: {0}",
Assembly.GetExecutingAssembly().GetName().Version);
Console.WriteLine("The version of mscorlib.dll is: {0}",
typeof(String).Assembly.GetName().Version);
}
}
答案 5 :(得分:1)
System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly();
System.Diagnostics.FileVersionInfo fvi = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
return fvi.ProductVersion;