Мы используем.Net 2.0 и вытаскиваем информацию о версии из блока. Возможно, не идеальный, но мы используем описание для хранения даты сборки.
Assembly assembly = Assembly.GetExecutingAssembly();
string version = assembly.GetName().Version.ToString();
string buildDate = ((AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(
assembly, typeof(AssemblyDescriptionAttribute))).Description;
процесс сборки использует asminfo nant задача генерировать файл AssemblyInfo.cs, который содержит эту информацию.
<asminfo output="Properties\AssemblyInfo.cs" language="CSharp">
<imports>
<import namespace="System" />
<import namespace="System.Reflection" />
<import namespace="System.Runtime.CompilerServices" />
<import namespace="System.Runtime.InteropServices" />
</imports>
<attributes>
<attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
<attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version}" />
<attribute type="AssemblyDescriptionAttribute" value="${datetime::now()}" />
...
</attributes>
</asminfo>
Я использую.NET 2.0 и 3.5, и она в состоянии установить обоих дата сборки и номер сборки. В то время как панель справки говорит, что, если.NET, которой уже позволяют, установила ее, это будет использовать случайное число для пересмотра, который не верен, она на самом деле помещает информацию о дате/времени, которая может быть легко извлечена, который подтвержден документами онлайн: http://msdn.microsoft.com/en-us/library/system.reflection.assemblyversionattribute.assemblyversionattribute.aspx
Видит этот блог: http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx?CommentPosted=true#commentmessage
я хочу установить версию сборки сам, но все еще хотеть автоматическую метку даты и времени, таким образом, я использую что-то вроде этого для AssemblyVersion ("1.0.*")
Вот демонстрационная функция для извлечения даты/времени сборки
private System.DateTime BuildDate()
{
//This ONLY works if the assembly was built using VS.NET and the assembly version attribute is set to something like the below. The asterisk (*) is the important part, as if present, VS.NET generates both the build and revision numbers automatically.
//<Assembly: AssemblyVersion("1.0.*")>
//Note for app the version is set by opening the 'My Project' file and clicking on the 'assembly information' button.
//An alternative method is to simply read the last time the file was written, using something similar to:
//Return System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly.Location)
//Build dates start from 01/01/2000
System.DateTime result = DateTime.Parse("1/1/2000");
//Retrieve the version information from the assembly from which this code is being executed
System.Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;
//Add the number of days (build)
result = result.AddDays(version.Build);
//Add the number of seconds since midnight (revision) multiplied by 2
result = result.AddSeconds(version.Revision * 2);
//If we're currently in daylight saving time add an extra hour
if (TimeZone.IsDaylightSavingTime(System.DateTime.Now, TimeZone.CurrentTimeZone.GetDaylightChanges(System.DateTime.Now.Year)))
{
result = result.AddHours(1);
}
return result;
}
Можно получить дату Сборки блока посредством отражения, проверить это примеры:
Я принял решение просто использовать дату выполняющегося блока. Путем я публикую файлы, это хорошо работает.
lblVersion.Text = String.Format("Version: {0}<br>Dated: {1}",
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(),
System.IO.File.GetLastWriteTime(System.Reflection.Assembly.GetExecutingAssembly().Location).ToShortDateString());