* 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:
parent
100e52a7c7
commit
55f5691eb3
3 changed files with 54 additions and 13 deletions
|
@ -32,12 +32,10 @@ using Microsoft.Build.Utilities;
|
||||||
|
|
||||||
namespace Build.Tasks
|
namespace Build.Tasks
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// Returns a date stamp in the form yyMMdd.
|
|
||||||
/// </summary>
|
|
||||||
public class DateStamp : Task
|
public class DateStamp : Task
|
||||||
{
|
{
|
||||||
string date;
|
string date;
|
||||||
|
const string file = "../../Version.txt";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a <see cref="System.String"/> represting the date stamp.
|
/// Gets a <see cref="System.String"/> represting the date stamp.
|
||||||
|
@ -53,12 +51,23 @@ namespace Build.Tasks
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Build number is defined as the number of days since 1/1/2010.
|
// Version.txt contains the datestamp for the current build.
|
||||||
// Revision number is defined as the fraction of the current day, expressed in seconds.
|
// This is used in order to sync stamps between build tasks.
|
||||||
double timespan = DateTime.UtcNow.Subtract(new DateTime(2010, 1, 1)).TotalDays;
|
// If the file does not exist, create it.
|
||||||
string build = ((int)timespan).ToString();
|
if (System.IO.File.Exists(file))
|
||||||
string revision = ((int)((timespan - (int)timespan) * UInt16.MaxValue)).ToString();
|
{
|
||||||
Date = String.Format("{0}.{1}", build, revision);
|
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)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
|
|
|
@ -48,7 +48,9 @@ namespace Build.Tasks
|
||||||
|
|
||||||
public GenerateAssemblyInfo()
|
public GenerateAssemblyInfo()
|
||||||
{
|
{
|
||||||
Date = new DateStamp().Date;
|
DateStamp stamp = new DateStamp();
|
||||||
|
stamp.Execute();
|
||||||
|
Date = stamp.Date;
|
||||||
Major = Major ?? "0";
|
Major = Major ?? "0";
|
||||||
Minor = Minor ?? "0";
|
Minor = Minor ?? "0";
|
||||||
}
|
}
|
||||||
|
@ -59,7 +61,7 @@ namespace Build.Tasks
|
||||||
|
|
||||||
using (StreamWriter sw = new StreamWriter(OutputFile, false, utf8))
|
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("// Do not edit by hand!");
|
||||||
sw.WriteLine();
|
sw.WriteLine();
|
||||||
|
|
||||||
|
|
|
@ -17,13 +17,43 @@
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="..\Build.Tasks\Common.xml" />
|
<Import Project="..\Build.Tasks\Common.xml" />
|
||||||
<Target Name="UpdateVersion">
|
<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>
|
||||||
<Target Name="Build">
|
<Target Name="Build">
|
||||||
<CallTarget Targets="UpdateVersion" />
|
<CallTarget Targets="UpdateVersion" />
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="Rebuild">
|
<Target Name="Rebuild">
|
||||||
<CallTarget Targets="UpdateVersion" />
|
<CallTarget Targets="Clean" />
|
||||||
|
<CallTarget Targets="Build" />
|
||||||
</Target>
|
</Target>
|
||||||
<Target Name="Clean" />
|
<Target Name="Clean" />
|
||||||
</Project>
|
</Project>
|
||||||
|
|
Loading…
Reference in a new issue