Skip to content

Instantly share code, notes, and snippets.

@Tewr
Created October 5, 2015 07:52
Show Gist options
  • Save Tewr/03cccc8cfe2081f30aaf to your computer and use it in GitHub Desktop.
Save Tewr/03cccc8cfe2081f30aaf to your computer and use it in GitHub Desktop.
BuildTimeInfo Setup
<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System" #>
<#@ output extension=".cs" #>
<#
string datePattern = "fffssmmHHddMMyyyy";
string buildTime = DateTime.Now.ToString(datePattern);
string humanReadableBuildTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:fff");
#>using System;
using System.Globalization;
public class BuildTimeInfo {
/// <summary>
/// The time this assembly was built (<#= humanReadableBuildTime#>)
/// </summary>
private static readonly DateTime buildTime = DateTime.ParseExact("<#= buildTime#>", "<#= datePattern#>", CultureInfo.InvariantCulture);
/// <summary>
/// Get the time this assembly was built (<#= humanReadableBuildTime#>)
/// </summary>
public static DateTime BuildTime {
get
{
return buildTime;
}
}
/// <summary>
/// A string description of when this assembly was built (returns "<#= humanReadableBuildTime#>")
/// </summary>
public const string BuildTimeString = "<#= humanReadableBuildTime#>";
}
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<None Include="RunT4.bat" />
<None Include="BuildTimeInfo.tt">
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>BuildTimeInfo.cs</LastGenOutput>
</None>
</ItemGroup>
<PropertyGroup>
<PreBuildEvent>..\..\RunT4.bat ..\..</PreBuildEvent>
</PropertyGroup>
</Project>
@echo off
REM äöäé
SETLOCAL ENABLEDELAYEDEXPANSION
:: set the working dir (default to current dir)
set wdir=%cd%
if not (%1)==() set wdir=%1
:: set the file extension (default to vb)
set extension=cs
if not (%2)==() set extension=%2
echo executing transform_all from %cd%
:: create a list of all the T4 templates in the working dir
dir %wdir%\*.tt /b /s > t4list.txt
echo the following T4 templates will be transformed:
type t4list.txt
:: transform all the templates
for /f "delims=" %%d in (t4list.txt) do (
set file_name=%%d
set file_name=!file_name:~0,-3!.%extension%
echo: \--^> !file_name!
echo Running "%COMMONPROGRAMFILES(x86)%\microsoft shared\TextTemplating\12.0\TextTransform.exe" -out "!file_name!" "%%d"
"%COMMONPROGRAMFILES(x86)%\microsoft shared\TextTemplating\12.0\TextTransform.exe" -out "!file_name!" "%%d"
)
echo transformation complete
@Tewr
Copy link
Author

Tewr commented Oct 5, 2015

Tested with Visual Studio Professional 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment