Here is my Code and it's working fine but its create .cs file under Enums.tt and the file name is Enums.generated.cs but I want to create an output file at my specific location in the project how can I achieve this?
Let me know is there any way to do this stuff. I searched for this but I didn't find any proper solution.
<#@ template debug="true" hostSpecific="false" #>
<#@ output extension=".generated.cs" #>
<#@ Assembly Name="System.Data" #>
<#@ import namespace="System.Data" #>
<#@ import namespace="System.Data.SqlClient" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#
string tableName = "ContentTypeMaster";
string columnId = "Id";
string columnName = "Name";
string connectionString = "Data Source=192.168.120.71;Initial Catalog=ErisWebsite;Persist Security Info=True;User ID=IM;Password=Intellimedia$#12;MultipleActiveResultSets=True;Connection Timeout=5000";
#>
using System;
using System.CodeDom.Compiler;
namespace ER.ErisCampaign.Enums
{
/// <summary>
/// <#= tableName #> auto generated enumeration
/// </summary>
public enum <#= tableName #>
{
<#
SqlConnection conn = new SqlConnection(connectionString);
string command = string.Format("select {0}, {1} from {2} order by {0}", columnId, columnName, tableName);
SqlCommand comm = new SqlCommand(command, conn);
conn.Open();
SqlDataReader reader = comm.ExecuteReader();
bool loop = reader.Read();
while(loop)
{
#> /// <summary>
/// <#= reader[columnName] #> configuration setting.
/// </summary>
<#= Pascalize(reader[columnName]) #> = <#= reader[columnId] #><# loop = reader.Read(); #><#= loop ? ",\r\n" : string.Empty #>
<#
}
#> }
}
<#+
private string Pascalize(object value)
{
Regex rx = new Regex(@"(?:[^a-zA-Z0-9]*)(?<first>[a-zA-Z0-9])(?<reminder>[a-zA-Z0-9]*)(?:[^a-zA-Z0-9]*)");
return rx.Replace(value.ToString(), m => m.Groups["first"].ToString().ToUpper() + m.Groups["reminder"].ToString().ToLower());
}
#>