Visual Studio Version 2017 Community Edition.
<#@ template debug="true" hostspecific="true" language="C#" #> <#@ output extension=".cs" #> <#@ import namespace="System.IO" #> <#@ import namespace="System.Text.RegularExpressions" #> <# string output = File.ReadAllText(this.Host.ResolvePath("AssemblyInfo.cs")); Regex pattern = new Regex("AssemblyVersion\\(\"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<revision>\\d+)\\.(?<build>\\d+)\"\\)"); MatchCollection matches = pattern.Matches(output); if( matches.Count == 1 ) { major = Convert.ToInt32(matches[0].Groups["major"].Value); minor = Convert.ToInt32(matches[0].Groups["minor"].Value); build = Convert.ToInt32(matches[0].Groups["build"].Value) + 1; revision = Convert.ToInt32(matches[0].Groups["revision"].Value); if( this.Host.ResolveParameterValue("-","-","BuildConfiguration") == "Release" ) revision++; } if( startYear != nowYear ){ appendYear = " - " + nowYear.ToString(); } #> // $Id$ // $URL$ using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Resources; // General Information [assembly: AssemblyTitle("FormApp-TEST")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("IT Raboese")] [assembly: AssemblyProduct("FormApp-Test")] [assembly: AssemblyCopyright("Copyright © IT Raboese <#= this.startYear #><#= this.appendYear #>")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] <#+ int major = 1; int minor = 0; int revision = 0; int build = 0; int startYear = 2011; int nowYear = DateTime.Now.Year; string appendYear = ""; #>
Im PreBuild-Event für das Projekt - muss noch diese Zeile eingefügt werden
"c:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\TextTransform.exe" "$(ProjectDir)Properties\AssemblyInfo.tt"
Der Compile dauert dadurch aber ein wenig länger.