<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ import namespace="System.IO" #>
<#@ output extension=".cs" #>

<#@ assembly name="EnvDTE" #><# /* This assembly provides access to Visual Studio project properties. */ #>
<#

	// Instructions
	// 1.  Add a new Text Template to the project
	// 2.  Copy this file into the new template
	// 3.  Update the string: versionfile with the complete path to the .version file
	// 4.  Remove the following line from the file AssemblyInfo.cs (usually located in the "Property" folder inside your C# project):
	//        [assembly: AssemblyVersion("1.0.0.0")]
	// 5.  Add the following to the PreBuild steps:
	//
	// set textTemplatingPath="%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Community\Common7\IDE\texttransform.exe"
	// %textTemplatingPath% "$(ProjectDir)AssemblyVersion.tt"


    int major = 0; 
    int minor = 0; 	
    int build = 0; 
	int patch = 0;
	bool versionSection = false;

	int i = 0;
	int i2 = 0;
	string s;
	
	// For Visual Studio / MSBuild Build-Time Template Resolution
	string RootDirectory = System.IO.Path.GetDirectoryName(Host.TemplateFile) + @"\..\";

	//
	// Update the following with the name of the .version file which is in the root directory
	//
	string versionfile = RootDirectory + "WarpDrive.version";


	if (!File.Exists(versionfile))
	{
		Write("File: " + versionfile + " missing\n");		
	}

	try
	{
		foreach (var line in File.ReadAllLines(versionfile))
		{
			if (line != null)
			{
				if (!versionSection)
				{
					if (line.Contains("\"VERSION\""))
						versionSection = true;
				}
				else
				{
					if (line.Contains("}"))
							versionSection = false;
					i = line.IndexOf(":");
					i2 = line.IndexOf(",");
					if (i2 == -1)
						i2 = line.Length;
					if (i >= 0 && i2 >= 0)
					{
						s = line.Substring(i + 1, i2 - i - 1);

						if (line.Contains("MAJOR"))			
							Int32.TryParse(s, out major);			
			
						if (line.Contains("MINOR"))			
							Int32.TryParse(s, out minor);
			
						if (line.Contains("PATCH"))			
							Int32.TryParse(s, out patch);
			
						if (line.Contains("BUILD"))			
							Int32.TryParse(s, out build);
					}
				}
			}
		}
         
     }
     catch
     {
         major = 1; 
         minor = 0; 
         patch = 0; 
         build = 0; 
     }
	 //Write("File done");

 #>
 // This code was generated by a tool. Any changes made manually will be lost
 // the next time this code is regenerated.
 // 
  
 using System.Reflection;

 [assembly: AssemblyVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")]
 [assembly: AssemblyFileVersion("<#= major #>.<#= minor #>.<#= patch #>.<#= build #>")]
