I have a template that is used to generate POCO's from the database. It's included below. When I execute the custom tool from inside Visual Studio all is well. However, when I execute it with the build through this package I get an error:
...\TableTemplate.tt(9,4): error : There was an error loading the include file 'T4Toolbox.tt'. The transformation will not be run. The following Exception was thrown:
System.IO.FileNotFoundException: Could not find file '...\T4Toolbox.tt'. (TaskId:14)
<#@ assembly name="System.Core" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#@ include file="T4Toolbox.tt" #>
<#+
public class TableTemplate : Template
{
Table tbl;
string classNamespace;
bool shouldBaseClientModel;
public TableTemplate(Table tbl, string classNamespace, bool shouldBaseClientModel)
{
this.tbl = tbl;
this.classNamespace = classNamespace;
this.shouldBaseClientModel = shouldBaseClientModel;
}
public override string TransformText()
{
#>
using System;
namespace <#= classNamespace #>
{
/// <summary>
/// Represents the <#= tbl.Name #> table.
/// NOTE: This class is generated from a T4 template - you should not modify it manually.
/// </summary>
public partial class <#= tbl.Name #><#+ if (shouldBaseClientModel) { #> : BaseClientModel<#+ } #>
{
<#+
// Keep count so we don't whitespace the last property/column
int columnCount = tbl.Columns.Count;
int i = 0;
// Iterate all columns
foreach (Column col in tbl.Columns)
{
i++;
string propertyType = GetNetDataType(col.DataType.Name);
// If we can't map it, skip it
if (string.IsNullOrWhiteSpace(propertyType))
{
continue;
}
// Handle nullable columns by making the type nullable
if (col.Nullable && propertyType != "string")
{
propertyType += "?";
}
#>
public <#= propertyType #> <#= col.Name #> { get; set; }
<#+
// Do we insert the space?
if (i != columnCount)
{
#>
<#+
}
}
#>
}
}
<#+
return this.GenerationEnvironment.ToString();
}
private static string GetNetDataType(string sqlDataTypeName)
{
switch (sqlDataTypeName.ToLower())
{
case "bigint":
return "Int64";
case "binary":
case "image":
case "varbinary":
return "byte[]";
case "bit":
return "bool";
case "char":
return "char";
case "datetime":
case "smalldatetime":
return "DateTime";
case "decimal":
case "money":
case "numeric":
return "decimal";
case "float":
return "double";
case "int":
return "int";
case "nchar":
case "nvarchar":
case "text":
case "varchar":
case "xml":
return "string";
case "real":
return "single";
case "smallint":
return "Int16";
case "tinyint":
return "byte";
case "uniqueidentifier":
return "Guid";
default:
return null;
}
}
}
#>
Looks like based on this SO post, it won't matter if I get this running because I can't get at the Host. I need the Host so that I can add these files to the project nicely. Oh well.
I have a template that is used to generate POCO's from the database. It's included below. When I execute the custom tool from inside Visual Studio all is well. However, when I execute it with the build through this package I get an error: