I am thinking of the following design:
我在考虑以下设计:
static class AppVersion
{
public static string BuildDate
{
get; set;
}
public static string Version
{
get; set;
}
public static string GetVersion
{
get; set;
}
}
A few questions on this:
关于这个的一些问题:
- How can I get the build date?
- How can I print a date in a nice format?
- How can I obtain and print the Visual Studio version in a nice format?
- It is probably a bad idea to hard code the version into the binary, so I put the version into assembly information. How can I programmatically get it?
我怎样才能获得构建日期?
如何以漂亮的格式打印日期?
如何以漂亮的格式获取和打印Visual Studio版本?
将版本硬编码到二进制文件中可能是一个坏主意,因此我将版本放入汇编信息中。我怎么能以编程方式获得它?
4 个解决方案
#1
I think your first questions are a matter of taste. You could use String.Format
to get any style you want. Regarding your last question:
我认为你的第一个问题是品味问题。你可以使用String.Format来获得你想要的任何风格。关于你的上一个问题:
System.Reflection.Assembly.GetExecutingAssembly().Version
returns the version number of the current assembly and:
返回当前程序集的版本号,并:
typeof(SomeTypeInSomeAssembly).Assembly.Version
will return the version number of the assembly containing the specific type.
将返回包含特定类型的程序集的版本号。
#2
We run all our production builds through CruiseControl.NET, which (among many other things) has the facility to version builds.
我们通过CruiseControl.NET运行我们所有的生产构建,CruiseControl.NET(以及许多其他东西)具有版本构建的功能。
We then have a snippet of code that applies the CC.NET-generated build number (and other stuff) to AssemblyInfo.cs just before it's given to the compiler for building.
然后我们有一段代码片段,它们将CC.NET生成的构建号(和其他东西)应用到AssemblyInfo.cs,就在它被提供给编译器进行构建之前。
I suppose you could use a similar technique to insert the build date into a constant in some class somewhere in your app.
我想你可以使用类似的技术将构建日期插入到应用程序中某个类的常量中。
#3
For build Date look at http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx
有关构建日期,请查看http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx
For the version / Get Version look at the System.Reflection.Assembly name space.
对于版本/获取版本,请查看System.Reflection.Assembly名称空间。
As for printing the date in a nice format, you'll want to either use the extension methods built off of DateTime class such as .ToShortDateString() or CultureInfo.
至于以漂亮的格式打印日期,您将要使用由DateTime类构建的扩展方法,如.ToShortDateString()或CultureInfo。
#4
For build date or timestamp, you can embed it into the assembly when building.
For how to do that, see here.
对于构建日期或时间戳,您可以在构建时将其嵌入到程序集中。如何做到这一点,请看这里。
#1
I think your first questions are a matter of taste. You could use String.Format
to get any style you want. Regarding your last question:
我认为你的第一个问题是品味问题。你可以使用String.Format来获得你想要的任何风格。关于你的上一个问题:
System.Reflection.Assembly.GetExecutingAssembly().Version
returns the version number of the current assembly and:
返回当前程序集的版本号,并:
typeof(SomeTypeInSomeAssembly).Assembly.Version
will return the version number of the assembly containing the specific type.
将返回包含特定类型的程序集的版本号。
#2
We run all our production builds through CruiseControl.NET, which (among many other things) has the facility to version builds.
我们通过CruiseControl.NET运行我们所有的生产构建,CruiseControl.NET(以及许多其他东西)具有版本构建的功能。
We then have a snippet of code that applies the CC.NET-generated build number (and other stuff) to AssemblyInfo.cs just before it's given to the compiler for building.
然后我们有一段代码片段,它们将CC.NET生成的构建号(和其他东西)应用到AssemblyInfo.cs,就在它被提供给编译器进行构建之前。
I suppose you could use a similar technique to insert the build date into a constant in some class somewhere in your app.
我想你可以使用类似的技术将构建日期插入到应用程序中某个类的常量中。
#3
For build Date look at http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx
有关构建日期,请查看http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx
For the version / Get Version look at the System.Reflection.Assembly name space.
对于版本/获取版本,请查看System.Reflection.Assembly名称空间。
As for printing the date in a nice format, you'll want to either use the extension methods built off of DateTime class such as .ToShortDateString() or CultureInfo.
至于以漂亮的格式打印日期,您将要使用由DateTime类构建的扩展方法,如.ToShortDateString()或CultureInfo。
#4
For build date or timestamp, you can embed it into the assembly when building.
For how to do that, see here.
对于构建日期或时间戳,您可以在构建时将其嵌入到程序集中。如何做到这一点,请看这里。