* Source/Build.Tasks/DateStamp.cs: Read/Write stamp from/to

Version.txt file. Allows a single stamp to be propagated throughout
  the build process.

* Source/Build.Tasks/GenerateAssemblyInfo.cs: Correctly invoke
  DateStamp task (need to call Execute() to generate the stamp).

* Source/Build.UpdateVersion/Build.UpdateVersion.csproj: Cleaned up
  'Rebuild' target.
Cleaned up 'GenerateAssemblyInfo' task invocation.
Attempted to generate GlobalAssemblyInfo.cs without using a custom
  task. Unfortunately, xbuild didn't wish to cooperate.
Remove Version.txt file to update the datestamp.
This commit is contained in:
the_fiddler 2010-10-06 08:47:01 +00:00
parent 100e52a7c7
commit 55f5691eb3
3 changed files with 54 additions and 13 deletions

View file

@ -32,12 +32,10 @@ using Microsoft.Build.Utilities;
namespace Build.Tasks
{
/// <summary>
/// Returns a date stamp in the form yyMMdd.
/// </summary>
public class DateStamp : Task
{
string date;
const string file = "../../Version.txt";
/// <summary>
/// Gets a <see cref="System.String"/> represting the date stamp.
@ -53,12 +51,23 @@ namespace Build.Tasks
{
try
{
// Build number is defined as the number of days since 1/1/2010.
// Revision number is defined as the fraction of the current day, expressed in seconds.
double timespan = DateTime.UtcNow.Subtract(new DateTime(2010, 1, 1)).TotalDays;
string build = ((int)timespan).ToString();
string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
Date = String.Format("{0}.{1}", build, revision);
// Version.txt contains the datestamp for the current build.
// This is used in order to sync stamps between build tasks.
// If the file does not exist, create it.
if (System.IO.File.Exists(file))
{
Date = System.IO.File.ReadAllLines(file)[0];
}
else
{
// Build number is defined as the number of days since 1/1/2010.
// Revision number is defined as the fraction of the current day, expressed in seconds.
double timespan = DateTime.UtcNow.Subtract(new DateTime(2010, 1, 1)).TotalDays;
string build = ((int)timespan).ToString();
string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
Date = String.Format("{0}.{1}", build, revision);
System.IO.File.WriteAllLines(file, new string[] { Date });
}
}
catch (Exception e)
{

View file

@ -48,7 +48,9 @@ namespace Build.Tasks
public GenerateAssemblyInfo()
{
Date = new DateStamp().Date;
DateStamp stamp = new DateStamp();
stamp.Execute();
Date = stamp.Date;
Major = Major ?? "0";
Minor = Minor ?? "0";
}
@ -59,7 +61,7 @@ namespace Build.Tasks
using (StreamWriter sw = new StreamWriter(OutputFile, false, utf8))
{
sw.WriteLine("// This file is auto-generated through Source.Build.Tasks/AssemblyInfo.cs.");
sw.WriteLine("// This file is auto-generated through Source/Build.Tasks/GenerateAssemblyInfo.cs.");
sw.WriteLine("// Do not edit by hand!");
sw.WriteLine();

View file

@ -17,13 +17,43 @@
</PropertyGroup>
<Import Project="..\Build.Tasks\Common.xml" />
<Target Name="UpdateVersion">
<GenerateAssemblyInfo OutputFile="..\GlobalAssemblyInfo.cs" AssemblyCompany="The Open Toolkit Library" AssemblyProduct="The Open Toolkit Library" AssemblyCopyright="Copyright © 2006 - 2010 the Open Toolkit Library" AssemblyTrademark="OpenTK" Major="1" Minor="0" />
<Delete Files="..\..\Version.txt" />
<GenerateAssemblyInfo
OutputFile="..\GlobalAssemblyInfo.cs"
AssemblyCompany="The Open Toolkit Library"
AssemblyProduct="The Open Toolkit Library"
AssemblyCopyright="Copyright © 2006 - 2010 the Open Toolkit Library"
AssemblyTrademark="OpenTK"
Major="1"
Minor="0" />
<!-- Fails because xbuild does not respect %3b
<DateStamp>
<Output TaskParameter="Date" PropertyName="ShortDate" />
</DateStamp>
<WriteLinesToFile File="..\GlobalAssemblyInfo.cs" Overwrite="true"
Lines='// This file is auto-generated through Build.UpdateVersion.csproj.;
// Do not edit by hand!;
using System%3b;
using System.Reflection%3b;
using System.Resources%3b;
using System.Runtime.CompilerServices%3b;
using System.Runtime.Runtime.InteropServices%3b;
;
[assembly: AssemblyCompany("The Open Toolkit Library")];
[assembly: AssemblyProduct("The Open Toolkit Library")];
[assembly: AssemblyCopyright("Copyright © 2006 - 2010 the Open Toolkit Library")];
[assembly: AssemblyTrademark("OpenTK")];
[assembly: AssemblyVersion("1.0.0.0")];
[assembly: AssemblyFileVersion("1.0.$(ShortDate)")];
' />
-->
</Target>
<Target Name="Build">
<CallTarget Targets="UpdateVersion" />
</Target>
<Target Name="Rebuild">
<CallTarget Targets="UpdateVersion" />
<CallTarget Targets="Clean" />
<CallTarget Targets="Build" />
</Target>
<Target Name="Clean" />
</Project>