如何使用GAX将参数传递给T4模板? [英] How to pass parameters to T4 templates using GAX?

查看:103
本文介绍了如何使用GAX将参数传递给T4模板?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有以下模板,由Clarius编辑器创建。当我右键单击并执行"预览转换"时,"属性"窗口中设置的值被正确替换,但实际的.cs文件(在解决方案中)未正确生成。我也得到一个编译错误:

错误1运行转换:System.ArgumentNullException:值不能为null。
参数名称:objectToConvert
在Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert )
at Microsoft.VisualStudio.TextTemplating71AC0EACE4EB44F4B73CCBE83655D590.GeneratedTextTransformation.TransformText()C:\TT \TemplateTest \ TemplateTest \ test.tt 1 1

有谁知道解决这个问题?



I have the following template, created by the Clarius editor. When I right click and do a "Preview Transformation", the values set in the Properties window are properly substituted, but the actual .cs file (in the solution) is NOT generated properly. I also get a compile error:

Error 1 Running transformation: System.ArgumentNullException: Value cannot be null.
Parameter name: objectToConvert
   at Microsoft.VisualStudio.TextTemplating.ToStringHelper.ToStringWithCulture(Object objectToConvert)
   at Microsoft.VisualStudio.TextTemplating71AC0EACE4EB44F4B73CCBE83655D590.GeneratedTextTransformation.TransformText() C:\TT\TemplateTest\TemplateTest\test.tt 1 1 

Does anyone know to fix this?




















< tr>






































< #@ template 语言 = " C#" >
< #@ assembly name = " System.dll" >
< #@ property 处理器 = " PropertyProcessor" name = " ClassName" ; type = " System.String,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089" >
< #@ property < font style ="color:red"> processor = " PropertyProcessor" name = " TargetNamespace" type = " System.String,mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089" >
< #@ property processor = " PropertyProcessor" name = " HelloMessage" type = " System.String, mscorlib,Version = 2.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089" >
使用System;
使用System.Text;
命名空间 < #= TargetNamespace# >
{
class < #= ClassName# >
{
公共静态字符串 helloMessage = < font style ="color:blue">"<#= HelloMessage#>" ;
static void Main(string [] args)
{
Console.WriteLine(helloMessage);
Console.ReadLine();
}
}
}
 
<#@ template language="C#" #> 
 
<#@ assembly name="System.dll" #> 
<#@ property processor="PropertyProcessor" name="ClassName" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #> 
<#@ property processor="PropertyProcessor" name="TargetNamespace" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #> 
<#@ property processor="PropertyProcessor" name="HelloMessage" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #> 
 
 
using System;  
using System.Text;  
 
namespace <#= TargetNamespace #> 
{  
    class <#= ClassName #> 
    {  
        public static string helloMessage = "<#= HelloMessage #>";  
          
        static void Main(string[] args)  
        {  
            Console.WriteLine(helloMessage);  
            Console.ReadLine();   
        }  
    }  
}  
 

推荐答案


我我不确定你是否试图使用这个样本,因为它看起来很相似。
http://weblogs.asp.net/jescrich /存档/ 2007/05/03 /测试-T4 -templates-使用-的-gax-host .aspx

如果有,你是否按原样使用样本?哪个gax和vs版本?

我做的示例基于默认的指导包,所以如果你只是尝试创建一个默认的指导包,你将得到一个完全相同的模板(Program.cs.t4 )。

你创建了自己的食谱吗?你可以发布食谱的样子。?

jose。
Hi,
I'm not sure if you're trying to use this sample, because it looks pretty same.
http://weblogs.asp.net/jescrich/archive/2007/05/03/testing-t4-templates-using-the-gax-host.aspx

if so, are you using the sample as is? which gax and vs version?

The sample that I made is based on a default guidance package so if you just try to create a default guidance package you'll get a exactly the same template (Program.cs.t4).

did you create your own recipe?, can you post how the recipe looks.?

jose.


这篇关于如何使用GAX将参数传递给T4模板?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆