标签: texttemplate

如何将字符串参数传递给t4模板

嗨,我想找到一种方法将普通字符串作为参数传递给文本模板.

这是我的模板代码,如果有人可以告诉我在c#中需要写什么来传递我的参数并创建类文件.这将非常有帮助,谢谢.

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ parameter name="namespacename" type="System.String" #>
<#@ parameter name="classname" type="System.String" #>
<#
this.OutputInfo.File(this.classname);
#>
namespace <#= this.namespacename #>
{
    using System;
    using System.Collections.Generic; 
    using System.Linq; 
    using System.Xml; 

    /// <summary>
    /// This class describes the data layer related to <#= this.classname #>.
    /// </summary>
    /// <history>
    ///   <change author=`Auto Generated` date=<#= DateTime.Now.ToString("dd/MM/yyyy") #>>Original Version</change> …
Run Code Online (Sandbox Code Playgroud)

c# string parameters t4 texttemplate

15
推荐指数
2
解决办法
1万
查看次数

在Visual Studio代码中执行T4文本模板

.tt在Visual Studio Code中创建了一个T4文本模板()文件,但与Visual Studio 2017(或2015,...)不同,它在保存文件后不会生成输出.tt文件.如何在Visual Studio Code中生成输出?

c# t4 code-generation texttemplate visual-studio-code

12
推荐指数
1
解决办法
2056
查看次数

T4 - TT - 在TT文件中使用自定义类

我想在我的TT中的CS文件中使用我自己的类定义.

例:

public class ClassDefinition
{
    public string NameSpace { get; set; }
    public string Name { get; set; }
    public string Protection { get; set; }

    List<ClassProperty> Properties { get; set; }
}
Run Code Online (Sandbox Code Playgroud)

我的TT看起来像:

<#@ template debug="true" hostspecific="true" language="C#" #>
<#@ output extension=".cs" #>

<#@ assembly name="System" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml"#>

<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.IO" #>

<#@ include file="$(ProjectDir)ClassDefinition.cs" #> …
Run Code Online (Sandbox Code Playgroud)

css c# t4 texttemplate

9
推荐指数
2
解决办法
1万
查看次数

如何在VS2010中指定使用C#4.0的T4(文本模板)?

我需要指定我的T4使用C#4.0来渲染我的tt文件?我试过用

<#@ template language="C#v4.0" debug="true" #>
Run Code Online (Sandbox Code Playgroud)

但是当我使用动态变量时,就像这样

dynamic x=10;
Write(x.ToString());
Run Code Online (Sandbox Code Playgroud)

我收到这些错误

Error   2   Compiling transformation: Predefined type 'Microsoft.CSharp.RuntimeBinder.CSharpSetMemberBinder' is not defined or imported e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   3   Compiling transformation: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder..ctor'  e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   4   Compiling transformation: Missing compiler required member 'System.Runtime.CompilerServices.CallSite.Create'    e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   5   Compiling transformation: One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?   e:\Projects\DynamicModel\DynamicModel\ModelGenerator.tt 7   8   
Error   6 …
Run Code Online (Sandbox Code Playgroud)

.net t4 texttemplate visual-studio-2010-beta-1 c#-4.0

5
推荐指数
1
解决办法
4324
查看次数

XCode的T4工具

XCode是否存在类似Visual Studio的T4文本模板生成工具?

感谢您的帮助,Enyra

t4 xcode code-generation texttemplate

5
推荐指数
1
解决办法
350
查看次数

T4和TextTemplatingFileGenerator

我在我的项目中使用T4.我有一个.tt文件,它是TextTemplatingFileGenerator我发现它不会生成输出,除非我编辑.tt文件.有没有办法通过构建或编译生成输出?这对我来说很重要,因为我在VS项目模板中添加了这个.tt文件,而这个.tt文件正在读取同一个项目模板中的另一个xml文件.并且项目模板将被所有其他开发人员使用.当开发人员编辑该xml文件并运行构建时,我想重新生成模板.我不想让所有开发人员在想要重新生成输出时修改.tt.谢谢

t4 text visual-studio-2010 texttemplate visual-studio-2008

5
推荐指数
1
解决办法
5375
查看次数

使用 .Net Core 的 T4 参数指令

当我尝试将参数发送到运行时文本模板 t4(网络核心)时,我在使用 .net Core 的“CallContext.LogicalGetData”方法中遇到问题

以下 tt 文件:

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ parameter name="firstName" type="System.String" #>
<#@ parameter name="lastName" type="System.String" #>
Run Code Online (Sandbox Code Playgroud)

和Cs调用方法:

            var pt1 = new ParamTemplate1();
            pt1.Session = new Dictionary<string, object>();
            pt1.Session["firstName"] = "David";
            pt1.Session["lastName"] = "Giard";
            pt1.Initialize();
            var outputText1 = pt1.TransformText();
            Console.WriteLine(outputText1);
             Hello <#=firstName #> <#=lastName #>!
Run Code Online (Sandbox Code Playgroud)

问题是由于 .net core 不支持“System.Runtime.Remoting”库

有什么想法或解决方法吗?

谢谢。

c# t4 texttemplate .net-core

5
推荐指数
1
解决办法
758
查看次数