Last active
February 8, 2018 18:32
-
-
Save drewchapin/8887b92f0aaf8b51f421993dae030ed0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Add this to pre-build event | |
// "%CommonProgramFiles(x86)%\microsoft shared\TextTemplating\$(VisualStudioVersion)\TextTransform.exe" -a !!BuildConfiguration!$(Configuration) "$(ProjectDir)Properties\AssemblyInfo.tt" | |
// | |
<#@ template debug="true" hostspecific="true" language="C#" #> | |
<#@ output extension=".cs" #> | |
<#@ import namespace="System.IO" #> | |
<#@ import namespace="System.Text.RegularExpressions" #> | |
using System.Reflection; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Resources; | |
// General Information | |
[assembly: AssemblyTitle("Project Title")] | |
[assembly: AssemblyDescription("Description")] | |
[assembly: AssemblyConfiguration("")] | |
[assembly: AssemblyCompany("Company")] | |
[assembly: AssemblyProduct("Product")] | |
[assembly: AssemblyCopyright("Copyright © 2018 Company Name")] | |
[assembly: AssemblyTrademark("Trademark")] | |
[assembly: AssemblyCulture("")] | |
// Version information | |
<# | |
string output = File.ReadAllText(this.Host.ResolvePath("AssemblyInfo.cs")); | |
Regex pattern = new Regex("^\\[assembly: AssemblyVersion\\(\"(?<major>\\d+)\\.(?<minor>\\d+)\\.(?<build>\\d+)(\\.[0-9\\*]+)?\"\\)\\]",RegexOptions.Multiline); | |
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); | |
if( this.Host.ResolveParameterValue("-","-","BuildConfiguration") == "Release" ) | |
{ | |
minor++; | |
build = 0; | |
} | |
else | |
build++; | |
} | |
else | |
WriteLine("// AssemblyInfo.tt could not find existing AssemblyVersion(). Using default values."); | |
#> | |
[assembly: AssemblyVersion("<#= this.major #>.<#= this.minor #>.<#= this.build #>")] | |
[assembly: AssemblyFileVersion("<#= this.major #>.<#= this.minor #>.<#= this.build #>")] | |
[assembly: NeutralResourcesLanguageAttribute( "en-US" )] | |
<#+ | |
public int major { get; set; } | |
public int minor { get; set; } | |
public int build { get; set; } | |
#> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment