problem trying to run templates in Visual Studio 2010

Mar 3, 2011 at 2:52 PM
Edited Mar 3, 2011 at 3:03 PM

All -

Please help.

I am having a major problem trying to run templates in Visual Studio 2010.

I have Visual Studio 2008 installed, I installed Visual Studio 2010, and now I opened my project and my T4 templates (which previously ran) do not run.

It seems to be looking for the include file "T4Toolbox.tt".

Can you help?

 

This is the offending "include" line...

<#@ include file="T4Toolbox.tt" #> 

 

These are the CTEs (Compile Time Errors) when the T4 tries to run...


Error 1

Failed to resolve include text for file:

C:\Code\Tester\Clearwater\Clearwater.BusinessLayer\BusinessManagers\Generated\T4Toolbox.tt

C:\Code\Tester\Clearwater\Clearwater.BusinessLayer\BusinessManagers\Generated\_T4L2sEntityManager03File.tt

0 0 Tester.Clearwater.BusinessLayer


Error 3

Loading the include file 'T4Toolbox.tt' returned a null or empty string.

The transformation will not be run.

C:\Code\Tester\Clearwater\Clearwater.BusinessLayer\BusinessManagers\Generated\_T4L2sEntityManager03File.tt

3 4

Error 4

Failed to resolve include text for file:

C:\Code\Tester\Clearwater\Clearwater.BusinessLayer\BusinessUtilities\Generated\T4Toolbox.tt

C:\Code\Tester\Clearwater\Clearwater.BusinessLayer\BusinessUtilities\Generated\_T4CodeUtility03File.tt

0 0

 

Thank you.

- Mark Kamoski

 

Mar 3, 2011 at 3:14 PM

 

All -

This is an update to the "cannot run t4Toolbox in VS 2010 issue" noted above.

In Visual Studio 2010 Pro, I went to this area in the IDE...

> Tools, > Options, > Environment, > Add-in/Macros Security, > Add-in File Paths

...and I added this path...

C:\Program Files\T4 Toolbox\

...because I found this file...

C:\Program Files\T4 Toolbox\T4Toolbox.tt

...at that location...

...and the previous CTEs have gone away...

...BUT...

...I am now getting the following CTE...

 


Error 2

A processor named 'T4Toolbox.DteProcessor' could not be found for the directive named 'dte'. 

The transformation will not be run.  The following Exception was thrown:

System.IO.FileNotFoundException: Failed to resolve type for directive processor T4Toolbox.DteProcessor.

   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolveDirectiveProcessor(String processorName)

   at Microsoft.VisualStudio.TextTemplating.Engine.ProcessCustomDirectives(ITextTemplatingEngineHost host, TemplateProcessingSession session, List`1 directivesToBeProcessed)

C:\Program Files\T4 Toolbox\T4Toolbox.tt

 

 

...and I am also getting the following CTE...

 


Error 3

A processor named 'T4Toolbox.TransformationContextProcessor' could not be found for the directive named 'TransformationContext'. 

The transformation will not be run.  The following Exception was thrown:

System.IO.FileNotFoundException: Failed to resolve type for directive processor T4Toolbox.TransformationContextProcessor.

   at Microsoft.VisualStudio.TextTemplating.VSHost.TextTemplatingService.ResolveDirectiveProcessor(String processorName)

   at Microsoft.VisualStudio.TextTemplating.Engine.ProcessCustomDirectives(ITextTemplatingEngineHost host, TemplateProcessingSession session, List`1 directivesToBeProcessed)

C:\Program Files\T4 Toolbox\T4Toolbox.tt

 


...so I am still stuck and in need of help.

What do you suggest?

Please advise.

Thank you.

- Mark Kamoski

Mar 3, 2011 at 4:01 PM

All -

I should have mentioned that this issue has cropped up coincidentally after my move from Windows XP Pro to Windows 7 Pro 32bit.

I just thought that I should mention this fact.

Any help is appreciated.

Thank you.

- Mark Kamoski

Mar 3, 2011 at 4:15 PM

All -

This is an update to the thread above.

I uninstalled T4Toolbox.

I reinstalled T4Toolbox, Version_10_3_7_1.

I tried to run the "Transform All Templates" command and I received this error...

Error 1

Compiling transformation: 

The type 'Microsoft.SqlServer.Management.Sdk.Sfc.ISfcValidate' is defined in an assembly that is not referenced. 

You must add a reference to assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=10.0.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91'.

c:\Code\Testing\Framework\CodeGeneration\_T4L2sEntityManager03Generator.tt

...and now I am working on fixing that...

...so what do you think?

Please advise.

Thank you.

- Mark Kamoski

Mar 3, 2011 at 9:56 PM

All -

This is an update.

Now I am getting just this error...

Error 2 Compiling transformation: An assembly with the same identity 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' has already been imported. Try removing one of the duplicate references. C:\Code\Testing\Clearwater\Clearwater.BusinessLayer\BusinessUtilities\Generated\_T4CodeUtility03File.tt

...which is really stinky because I cannot make it go away.

If you HELP then please do send it along.

(In the meanwhile, I will continue to pull out my hair.)

Thank you.

- Mark Kamoski

Mar 4, 2011 at 6:43 PM

All -

This is an update.

After trying to (somehow) find the right combination of "import" directives and "assemby" directives to please Visual Studio 2010, I ended up with this transformation-time-error...

Error 1

 Compiling transformation:

The type or namespace name 'Data' does not exist in the namespace 'System' (are you missing an assembly reference?)

c:\Users\kamoskim\AppData\Local\Temp\h2hmurhv.0.cs 

...and so I reset the references in all projects to the "System.dll" and the "System.Data.dll" but still this transformation-time-error keeps coming up.

...so, ug, I rolled back the offending TT files to their pre-Visual-Studio-2010 glory and opened the project in Visual-Studio-2008 and transformation-time works fine... 

...so, sad to say, I am thinking that there IS some kind of issue with T4Toolbox (or maybe in the internals of T4 itself?) that is not directly compatible when moving from Visual Studio 2008 to Visual Studio 2010...

...so, that is the "conclusion" I have for now but I would be more than happy to find out exactly how to migrate my T4 templates into Visual Studio 2010.

Please do post info on this if you have any, etc.

Thank you.

- Mark Kamoski

 

Mar 4, 2011 at 6:52 PM

 

All -

BTW, I think (but I am not certain) that the "issue" I am having comes from a particular TT set that I am using.

I use a TT development design where I have 2 TT pieces that are reusable (they are not-project-specific) and 1 TT piece that is not-reusable (it is project-specific).

I have listed each below, in case someone wants to try to unravel this a bit.

HTH.

Thank you.

- Mark Kamoski

 

 

.......... _T4CodeUtility03File.tt begin

<#@ template language="C#v3.5" hostspecific="True" debug="True" #> 
<#@ output extension="txt" #> 
<#@ include file="T4Toolbox.tt" #> 
<#@ include file="C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Generator.tt" #> 
<# 

	//For details concerning this file, see...
	//C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Generator.tt

	//Instantiate a new generator.
    _T4CodeUtility03Generator myGenerator = new _T4CodeUtility03Generator(); 
    
    //TODO. Set the values below to match your desired project settings.
    
    //This is the namespace that will be used for the the output classes.
    myGenerator.CodeUtilityNamespace = "Tester.ProjectAbc.BusinessLayer.BusinessUtilities";
    
    //This is the prefix that will be used for the the output classnames and filenames.
    myGenerator.CodeUtilityPrefix = string.Empty;
    
    //This is the suffix that will be used for the the output classnames and filenames.
    myGenerator.CodeUtilitySuffix = "Utility";
    
    //This is the database-name to use for all operations.
    myGenerator.DatabaseName = "ProjectAbc"; 
    
    //This is the database-server-name to use for all operations.
    myGenerator.ServerName = "Tester-db";
    
    //This is the list of code-table prefixes, where if a table name starts with any prefix in the list then that table is a "code table".
    myGenerator.CodeTablePrefixPsv = string.Empty;
    
    //This is the list of code-table suffixes, where if a table name starts with any prefix in the list then that table is a "code table".
    myGenerator.CodeTableSuffixPsv = "Code";
    
    //This is the list of column names, where one must exist in each code-table.
    myGenerator.CodeValueColumnNamePsv = "Name|NameText";
    
    //This is the database-login-secure setting to use for all operations, where True=UseWindowsAuthentication and False=UseSqlAuthentication.
    myGenerator.DatabaseLoginSecure = true;

	//This is the database-login-name to use for all operations.
    myGenerator.DatabaseLoginUsername = string.Empty;
    
    //This is the database-login-password to use for all operations.
    myGenerator.DatabaseLoginPassword = string.Empty;

	//Execute the generator.    
    myGenerator.Run(); 
#>

.......... _T4CodeUtility03File.tt end

.......... _T4CodeUtility03Generator.tt begin

<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ assembly name="System.Data" #>
<#@ assembly name="C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll" #> 
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Collections.ObjectModel" #>
<#@ include file="C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Template.tt" #>

<#+

//This T4 template set consists of the following files...
//YOUR_PROJECT_PATH_GOES_HERE\_T4CodeUtility03File.tt 
//C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Generator.tt
//C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Template.tt
//
//The purpose of this template set is to...
//...generate helpers that expose semi-static, code-table values for programmatic access, for filtering etc.
//
//Note that "Psv" stands for "pipe-separated-values", where the pipe-character (|) is used as a separator for a delimited-list.
//The file "*.File.tt" uses the file "*.Generator.tt"; and, the file "*.Generator.tt" uses the file "*.Template.tt".
//The number in the file name is the "version number" of this template set; use the highest available.
//This does generate ".cs" files. 
//This does not generate ".vb" files.
//Note that a "code-table" is loosely defined here, generally AKA "lookup table", AKA "list of values", AKA "type table", etc.
//Note that a "view-object" here is a "database View".
//To use this set, copy a sample "*.File.tt" to your project, set the project values below, and "Run Custom Tool" or "Transform All Templates".
//
//Note that a "code-table" here must have a single-column case-insensitive-unique text value.
//Note that the output class may be used in many ways.
//For example, to make a call to the built-in method this.User.IsInRole(string targetRoleName), such as to enforce the business rule 
//that says "hide this button if the user is not in the 'admin' role", then one must have somewhere hardcoded that targetRoleName.
//Generally, one either hard-codes the value somewhere or do this one does other odd tricks, each of which is manually maintained. 
//Objection 1: If the code table value gets deleted or changed then you have to recompile.
//Answer 1: Well, what better way is there to solve the issue of calling IsUserInRole() with a string role name?
//This is not for everyone or everything. 
//The hand-hardcode would break too and this is easier to maintain. 
//Also, this risk can be mitigated by a controlled admin workflow and other code.
//Also, this is intended for semi-static, system-level values.

public class _T4CodeUtility03Generator : Generator
{
    public bool DatabaseLoginSecure;
    public bool OverwriteExisting;
    
    public string CodeTablePrefixPsv;
    public string CodeTableSuffixPsv;
    public string CodeUtilityNamespace;
    public string CodeUtilityPrefix;
    public string CodeUtilitySuffix;
    public string CodeValueColumnNamePsv;
    public string DatabaseLoginPassword;
    public string DatabaseLoginUsername;
    public string DatabaseName; 
	public string ServerName;

	public _T4CodeUtility03Template DefaultCodeUtilityTemplate = new _T4CodeUtility03Template();

    public string GetDateTimeGenerated()
    {
		string myDateTime = string.Empty;

		myDateTime = DateTime.Now.ToString("o"); 
		
		return myDateTime;
	}

	public string ConvertToPascalCase(string str)
	{
		//http://www.dreamincode.net/code/snippet2490.htm
		//if nothing is proivided throw a null argument exception
		if (str == null) throw new ArgumentNullException("str", "Null text cannot be converted!");

		//Hardjump.
		if (str.Length == 0) return str;
	
		//split the provided string into an array of words
		string[] words = str.Split(' ');
		
		//loop through each word in the array
		for (int i = 0; i < words.Length; i++)
		{
			//if the current word is greater than 1 character long
			if (words[i].Length > 0)
			{
				//grab the current word
				string word = words[i];
	
				//convert the first letter in the word to uppercase
				char firstLetter = char.ToUpper(word[0]);
	
				//concantenate the uppercase letter to the rest of the word
				words[i] = firstLetter + word.Substring(1);
			}
		}
	
		//return the converted text
		return string.Join(string.Empty, words);
	}	
	
    public string GetConnectionString(bool targetLoginSecureFlag, string targetDatabaseName, string targetServerName, string targetUserName, string targetPassword)
    {
		string myConnectionString = string.Empty;
		
		if (targetDatabaseName == null)
		{
			targetDatabaseName = (targetDatabaseName + string.Empty);
		}
		
		if (targetServerName == null)
		{
			targetServerName = (targetServerName + string.Empty);
		}
		
		if (targetUserName == null)
		{
			targetUserName = (targetUserName + string.Empty);
		}

		if (targetPassword == null)
		{
			targetPassword = (targetPassword + string.Empty);
		}
		
		if (targetLoginSecureFlag)
		{
			myConnectionString = "Integrated Security=SSPI; Initial Catalog=" + targetDatabaseName + "; Data Source=" + targetServerName + ";";
		}
		else
		{
			myConnectionString = "Data Source=" + targetServerName + ";Persist Security Info=True;Password=" + targetPassword + ";User ID=" + targetUserName + ";Initial Catalog=" + targetDatabaseName + ";";
		}

		return myConnectionString;
    }
	
    public string GetDbObjectNameCleaned(string targetValue)
    {
		string myValueCleaned = (targetValue + string.Empty).Trim();

		//Replace underscores with spaces.
		if (myValueCleaned.Contains("_"))
		{
			myValueCleaned = myValueCleaned.Replace("_", " ");	
		}

		//Remove any multiple-space sequences.
		while (myValueCleaned.Contains("  "))
		{
			myValueCleaned = myValueCleaned.Replace("  ", " ");
		}
		
		//Remove any spaces.
		if (myValueCleaned.Contains(" "))
		{
			myValueCleaned = this.ConvertToPascalCase(myValueCleaned);
			myValueCleaned = myValueCleaned.Replace(" ", string.Empty);	
		}
		
		return myValueCleaned;
    }
	
	public bool IsCodeTable(string targetTableNameActual)
	{
		bool isCodeTableFlag = false;
		
		targetTableNameActual = (targetTableNameActual + string.Empty).Trim().ToLower();
	
		//Check for prefix.
	
		string[] myCodeTablePrefixArray = this.CodeTablePrefixPsv.Trim().ToLower().Split('|'.ToString().ToCharArray());
        
        foreach (string myPrefixTemp in myCodeTablePrefixArray)
        {
			if (isCodeTableFlag)
			{
				//Continue. Pseudo-short-circuit. All we need to do is find one match.
			}
			else
			{
				if ((myPrefixTemp.Trim().ToLower().Length > 0) && (targetTableNameActual.StartsWith(myPrefixTemp.Trim().ToLower())))
				{
					isCodeTableFlag = true;
				}
			}
        }
        
        //Check for suffix.
        
		if (isCodeTableFlag)
		{
			//Continue. All we need to do is find one match.
		}
		else
		{
			string[] myCodeTableSuffixArray = this.CodeTableSuffixPsv.Trim().ToLower().Split('|'.ToString().ToCharArray());
	        
			foreach (string mySuffixTemp in myCodeTableSuffixArray)
			{
				if (isCodeTableFlag)
				{
					//Continue. Pseudo-short-circuit. All we need to do is find one match.
				}
				else
				{
					if (mySuffixTemp.Trim().ToLower().Length > 0 && targetTableNameActual.EndsWith(mySuffixTemp.Trim().ToLower()))
					{
						isCodeTableFlag = true;
					}
				}
			}
		}
      
		return isCodeTableFlag;
	}
	
	public string GetColumnNameToUse(Microsoft.SqlServer.Management.Smo.Table targetSmoTable)
	{
		string myColumnNameToUse = string.Empty;
		
		if (targetSmoTable == null)
		{
			throw new System.ApplicationException("The given object, targetSmoTable, is null.");
		}
		
		string[] myCodeValueColumnNameListArray = this.CodeValueColumnNamePsv.Trim().ToLower().Split('|'.ToString().ToCharArray());
		Array.Sort(myCodeValueColumnNameListArray);
		bool isFound = false;
		int mySearchResultTemp = int.MinValue;
		
		foreach (Microsoft.SqlServer.Management.Smo.Column mySmoColumpTemp in targetSmoTable.Columns)
		{
			if (isFound)
			{
				//Continue. Pseudo-short-circuit. We need to find only one.
			}
			else
			{
				mySearchResultTemp = Array.BinarySearch(myCodeValueColumnNameListArray, mySmoColumpTemp.Name.Trim().ToLower());
				
				if (mySearchResultTemp >= 0)
				{
					myColumnNameToUse = mySmoColumpTemp.Name;
					isFound = true;	
				}
			}
		}

		if (!isFound)
		{
			throw new System.ApplicationException("The targetSmoTable.Name='" + targetSmoTable.Name + 
				"' does not contain any column in the list CodeValueColumnNamePsv='" + CodeValueColumnNamePsv + "'.");
		}
		
		return myColumnNameToUse;
	}

	protected override void RunCore()
	{
		this.DefaultCodeUtilityTemplate.CodeUtilityNamespace = this.CodeUtilityNamespace;
		this.DefaultCodeUtilityTemplate.CodeUtilityPrefix = this.CodeUtilityPrefix;
		this.DefaultCodeUtilityTemplate.CodeUtilitySuffix = this.CodeUtilitySuffix;
		this.DefaultCodeUtilityTemplate.DatabaseName = this.DatabaseName;
		this.DefaultCodeUtilityTemplate.ServerName = this.ServerName;
		this.DefaultCodeUtilityTemplate.ConnectionString = this.GetConnectionString(this.DatabaseLoginSecure, this.DatabaseName, this.ServerName, this.DatabaseLoginUsername, this.DatabaseLoginPassword);
		this.DefaultCodeUtilityTemplate.DatabaseLoginPassword = this.DatabaseLoginPassword;
		this.DefaultCodeUtilityTemplate.DatabaseLoginUsername = this.DatabaseLoginUsername;
		this.DefaultCodeUtilityTemplate.DateTimeGenerated = this.GetDateTimeGenerated();

		Microsoft.SqlServer.Management.Common.ServerConnection mySmoConnection = new Microsoft.SqlServer.Management.Common.ServerConnection(); 
		mySmoConnection.LoginSecure = this.DatabaseLoginSecure; 
		
		if (!this.DatabaseLoginSecure)
		{   
		    mySmoConnection.Login = this.DatabaseLoginUsername;
		    mySmoConnection.Password = this.DatabaseLoginPassword;
		}
		
		mySmoConnection.ServerInstance = this.ServerName;
		mySmoConnection.DatabaseName = this.DatabaseName;
		Microsoft.SqlServer.Management.Smo.Server myDatabaseServer = new Microsoft.SqlServer.Management.Smo.Server(mySmoConnection);
        Microsoft.SqlServer.Management.Smo.Database myDatabase = new Microsoft.SqlServer.Management.Smo.Database(myDatabaseServer, this.DatabaseName);
        
        myDatabase.Refresh();
        string myColumnNameToUseTemp = string.Empty;
        string myTableNameCleanedTemp = string.Empty;
        string myTableNameActualTemp = string.Empty;
        int myCountOfCodeTablesFound = 0;
        string myFileNameTemp = string.Empty;

        foreach (Microsoft.SqlServer.Management.Smo.Table myTableTemp in myDatabase.Tables)
        {
			if (this.IsCodeTable(myTableTemp.Name))
			{
				myCountOfCodeTablesFound = myCountOfCodeTablesFound + 1;
				myTableNameActualTemp = myTableTemp.Name;
				myTableNameCleanedTemp = this.GetDbObjectNameCleaned(myTableTemp.Name);
				myColumnNameToUseTemp = this.GetColumnNameToUse(myTableTemp);
				
				this.DefaultCodeUtilityTemplate.ColumnName = myColumnNameToUseTemp;
				this.DefaultCodeUtilityTemplate.TableNameActual = myTableNameActualTemp;
				this.DefaultCodeUtilityTemplate.TableNameCleaned = myTableNameCleanedTemp;
				
				myFileNameTemp = this.CodeUtilityPrefix + myTableNameCleanedTemp + this.CodeUtilitySuffix + ".cs";
				
				//old
				this.DefaultCodeUtilityTemplate.RenderToFile(myFileNameTemp);
				
				//new
				//this.DefaultCodeUtilityTemplate.RenderToFile(myFileNameTemp, this.OverwriteExisting);v
			}
        }

		//TODO. 20091202. Remove if stale.
        //if (myCountOfCodeTablesFound <= 0)
		//{
		//	throw new System.ApplicationException(
		//		"The number of code tables found is myCountOfCodeTablesFound='" + 
		//		myCountOfCodeTablesFound.ToString() + "'.");
		//}
        
	}
}
#>

.......... _T4CodeUtility03Generator.tt end


.......... _T4CodeUtility03Template.tt begin

<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ assembly name="System.Data" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#@ import namespace="System" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#+

//To get details concerning this template set, see the comments in the file...
//C:\Code\Tester\Framework\CodeGeneration\_T4CodeUtility03Generator.tt

public class _T4CodeUtility03Template : Template
{
	public string CodeUtilityPrefix;
	public string CodeUtilitySuffix;
	public string CodeUtilityNamespace;
	public string ConnectionString;
	public string ColumnName;
    public string DatabaseLoginPassword;
    public string DatabaseLoginUsername;
	public string DatabaseName;
	public string DateTimeGenerated;
	public string ServerName;
    public string TableNameActual;
    public string TableNameCleaned;
    
    public string GetCellValueCleaned(string targetValue)
    {
		string myValueCleaned = (targetValue + string.Empty).Trim();
		
		//TODO. 20090805. Rewrite this with regular expressions or char.IsX() or similar.
		
		//Chars, top-row...
		
		myValueCleaned = myValueCleaned.Replace("~", "_");
		myValueCleaned = myValueCleaned.Replace("@", "_");
		myValueCleaned = myValueCleaned.Replace("#", "_");
		myValueCleaned = myValueCleaned.Replace("$", "_");
		myValueCleaned = myValueCleaned.Replace("%", "_");
		myValueCleaned = myValueCleaned.Replace("^", "_");
		myValueCleaned = myValueCleaned.Replace("&", "_");
		myValueCleaned = myValueCleaned.Replace("*", "_");
		myValueCleaned = myValueCleaned.Replace("(", "_");
		myValueCleaned = myValueCleaned.Replace(")", "_");
		myValueCleaned = myValueCleaned.Replace("+", "_");
		
		myValueCleaned = myValueCleaned.Replace("{", "_");
		myValueCleaned = myValueCleaned.Replace("}", "_");
		myValueCleaned = myValueCleaned.Replace("|", "_");
		
		myValueCleaned = myValueCleaned.Replace(":", "_");
		myValueCleaned = myValueCleaned.Replace("\"", "_");
		
		myValueCleaned = myValueCleaned.Replace("<", "_");
		myValueCleaned = myValueCleaned.Replace(">", "_");
		myValueCleaned = myValueCleaned.Replace("?", "_");
		
		//Chars, bottom-row...

		myValueCleaned = myValueCleaned.Replace("`", "_");
		myValueCleaned = myValueCleaned.Replace("-", "_");
		myValueCleaned = myValueCleaned.Replace("=", "_");
		myValueCleaned = myValueCleaned.Replace("[", "_");
		myValueCleaned = myValueCleaned.Replace("]", "_");
		myValueCleaned = myValueCleaned.Replace("\\", "_");
		myValueCleaned = myValueCleaned.Replace(";", "_");
		myValueCleaned = myValueCleaned.Replace("'", "_");
		myValueCleaned = myValueCleaned.Replace(",", "_");
		myValueCleaned = myValueCleaned.Replace(".", "_");
		myValueCleaned = myValueCleaned.Replace("/", "_");
		
		//Space...
		myValueCleaned = myValueCleaned.Replace(" ", "_");
		
		while (myValueCleaned.Contains("__"))
		{
			myValueCleaned = myValueCleaned.Replace("__", "_");
		}
		
		myValueCleaned = myValueCleaned.ToUpper();
		
		if (!myValueCleaned.StartsWith("_"))
		{
			myValueCleaned = "_" + myValueCleaned;
		}

		if (!myValueCleaned.EndsWith("_"))
		{
			myValueCleaned = myValueCleaned + "_";
		}
		
		return myValueCleaned;
    }

    public override string TransformText()
    {
		//Get data.

        System.Data.DataTable myDataTable = new DataTable();

		using (System.Data.SqlClient.SqlConnection myConnectionTemp = new System.Data.SqlClient.SqlConnection(this.ConnectionString))
		{
			System.Data.SqlClient.SqlDataAdapter myAdapter = new System.Data.SqlClient.SqlDataAdapter(" select * from [" + this.TableNameActual + "] order by [" + this.ColumnName + "] asc ", myConnectionTemp);
			myAdapter.Fill(myDataTable);
		}
#>

namespace <#= this.CodeUtilityNamespace #>
{
	/// 
	/// This is a helper to support the given entity.
	/// 
	/// 
	/// This code was generated '<#= this.DateTimeGenerated #>' and it should not be modified manually.
	/// 
	public static partial class <#= this.CodeUtilityPrefix #><#= this.TableNameCleaned #><#= this.CodeUtilitySuffix #>
	{
		#region Classes (1)
		
		/// 
		/// This is a helper to support run-time-conversion and consumer-friendly-lookup.
		/// 
		public static class NameText
		{
<#+
        PushIndent("\t");
        PushIndent("\t");
        PushIndent("\t");
        
        string myCellValueActualTemp = string.Empty;
        string myCellValueCleanedTemp = string.Empty;
		
		if (myDataTable.Rows.Count > 0)
		{
			WriteLine("#region StaticFields (" + myDataTable.Rows.Count.ToString() + ")");
		}
		
        foreach (DataRow myDataRowTemp in myDataTable.Rows)
        {
            myCellValueActualTemp = myDataRowTemp[this.ColumnName].ToString().Trim();
	        myCellValueCleanedTemp = this.GetCellValueCleaned(myDataRowTemp[this.ColumnName].ToString());
			
			WriteLine(" ");
			WriteLine("///  ");
			WriteLine("/// This is the code value. ");
			WriteLine("///  ");
            WriteLine("public const string " + myCellValueCleanedTemp + " = \"" + myCellValueActualTemp + "\";");
        }

		if (myDataTable.Rows.Count > 0)
		{
			WriteLine(" ");
			WriteLine("#endregion");
		}
		
        PopIndent();
        PopIndent();
        PopIndent();
#>
		}
		
		#endregion
	}
}
<#+
		
		return this.GenerationEnvironment.ToString();
	} //TransformText_Closing_Brace
} //class_Closing_Brace

#>

.......... _T4CodeUtility03Template.tt end

 

Coordinator
May 7, 2011 at 4:13 PM

Mark,

Have you been able to resolve this issue? It appears to be caused by a failed installation of the T4 Toolbox.

Oleg

Jun 7, 2011 at 11:49 PM

Mark, Oleg,

I am having the precise problem Mark has tried to address here.  I cannot roll back to a VS2008 solution, I am tied heavily to .Net4 / VS2010 and have been for over a year.  

Anything I can do to track down the failed installation?  

I looked at the windows event log and on both the installs of T4Toolbox I ended up with a ton of Application log entries like this:

Error in Template (C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\CSharp\Code\1033\Class.zip), file (Class.vstemplate).  Unregistered ProjectType (CSharp).  This can be caused by an incorrect ProjectType or because the project type package is not installed. 

This is odd, no?

Any help greatly appreciated.

Thanks

Coordinator
Jul 1, 2011 at 3:28 PM

Is C# installed as part of your Visual Studio? Which edition are you using?

Jul 1, 2011 at 10:20 PM

Hi Oleg,

C# is my main development language so is indeed installed.

I use VS2010 Premium.

Thanks

Simon

From: OlegSych [email removed]
Sent: Friday, July 01, 2011 9:28 AM
To: Simon Whitear
Subject: Re: problem trying to run templates in Visual Studio 2010 [t4toolbox:248308]

From: OlegSych

Is C# installed as part of your Visual Studio? Which edition are you using?



This e-mail and its attachments are intended only for the individual or entity to whom it is addressed and may contain information that is confidential, privileged, inside information, or subject to other restrictions on use or disclosure. Any unauthorized use, dissemination or copying of this transmission or the information in it is prohibited and may be unlawful. If you have received this transmission in error, please notify the sender immediately by return e-mail, and permanently delete or destroy this e-mail, any attachments, and all copies (digital or paper). Unless expressly stated in this e-mail, nothing in this message should be construed as a digital or electronic signature.
Aug 17, 2011 at 1:21 PM

I have the same issue while trying to setup regenerating all templates before build. Unfortunately, can't fix it.

Feb 1, 2012 at 1:13 PM

 

All --

I just thought I should shared an update regarding my current status using the "T4Toolbox.10.3.7.1.msi" and my custom T4 Template set in Visual Studio 2010 and Sql Server 2005.

In short, everything is working great.

In order to fix my templates, I simply removed some of the code dependencies on Sql Management Objects (SMO), which included removing all use of Microsoft.SqlServer.ConnectionInfo and Microsoft.SqlServer.Smo and Microsoft.SqlServer.Management.Smo and related namespaces. I now use the good good-old Information Schema Views and SqlClient and it works fine.

HTH.

Thanks.

-- Mark Kamoski