我有一个VS项目,其中包含:
TextTransform
在a template.tt
上运行的预构建操作以生成generated.cs
generated.cs
列为要编译的文件之一(即在项目文件列表中)
当我构建项目时,执行预构建操作,generated.cs
重新创建,但VS编译以前的版本generated.cs
(我猜它在构建过程开始时加载到内存中).
如何使构建使用新版本generated.cs
(即在预构建操作中生成的版本)?如何强制构建订单?
请注意,文本转换输入是动态的,因此无法在设计时完成.
我正在编写生成C#代码的软件.大多数情况下,我使用StringTemplate和StringBuilder.
有没有办法直接从我的代码中使用T4模板?
当我编辑T4时,每次切换到另一个文件时都会执行脚本.对于快速简单的脚本是可以的,但是一些脚本需要很长时间才能执行.有没有办法禁用这种行为?我希望脚本只在我保存T4文件时运行或从菜单中手动选择"运行自定义工具".
我有T4模板(mycode.tt),它生成一个cs文件.我通常右键单击tt文件并选择RunCustomTool,它在内部获取xml文件并为我生成代码.现在我想使用ac #windows应用程序运行自定义工具.因此,只需单击一个按钮即可运行自定义工具.是否可以从c#运行CustomTool.
编辑:
我有2个tt文件,其中一个没有codebehind cs文件.但另一个附加了.cs文件,我从第一个.tt文件调用第二个文件的TransformText()方法.所以我需要调用第一个文件.所以我不能使用TransformText()方法.有没有办法动态调用textTemplate文件?
当我得到以下compilaton错误时,我正在Visual Studio 2010下开发一个C#T4预处理模板:
包含类功能的模板必须以类功能结束
任何有类似问题的人,在创建webservices时?
编译转型:元数据文件 'd:\ Program Files文件\ VS2013\Common7 \工具..\IDE\Microsoft.Data.Entity.Design.dll' 无法找到d:\ PROJEKTY\apki\WS2\WS\WS \的DataModel .TT
我尝试再次添加数据模型,重新启动VS,清理和构建解决方案,创建新项目,删除和添加引用,安装最新版本.我认为在互联网上找到的任何解决方案对我都不起作用.
有什么建议?我想把文件粘贴到这个目录中,但不能想到可能存在的内容.
t4 entity-framework ado.net-entity-data-model visual-studio-2013
我目前正在使用T4模板,我注意到有时代码没有正确缩进,我怎么能避免这种情况?
例如,我在模板中有这个代码
}
<# } #>
this.cmbDecisionList.Dat = dataSource;
this.btnDec.Enabled = dataSource.Count > 0;
}
Run Code Online (Sandbox Code Playgroud)
在生成的类中它就像
}
this.cmbDecisionList.Dat = dataSource;
this.btnDec.Enabled = dataSource.Count > 0;
}
Run Code Online (Sandbox Code Playgroud) 试图为Immutable Object Graph运行T4模板会产生错误
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
? Error ? 5 ? Compiling transformation: Invalid token 'this' in class, struct, or interface member declaration ? c:\dev\ImmutableObjectGraph-master\2013\Demo\Message.tt ? 1 ? 1 ? Demo ?
? Error ? 6 ? Compiling transformation: Method must have a return type ? c:\dev\ImmutableObjectGraph-master\2013\Demo\Message.tt ? 1 ? 6 ? Demo ?
? Error ? 7 ? Compiling transformation: Type expected ? c:\dev\ImmutableObjectGraph-master\2013\Demo\Message.tt ? 1 ? 12 ? Demo ?
??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????
Run Code Online (Sandbox Code Playgroud)
报告的行始终是第1行,并且完整的t4模板集是数百行.如何解决并解决此问题?
在Visual Studio 2015中,我正在使用NuGet包Unofficial.Microsoft.VisualStudio.TextTemplating.14.0.0
,它允许我在构建项目时直接从MSBuild转换T4模板.
但是,在Visual Studio 2017 RTM中,这会使用以下消息中断构建:
An Exception was thrown while running the transformation code. The process cannot continue. The following Exception was thrown:
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.
File name: 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
这是Unofficial.Microsoft.VisualStudio.TextTemplating.targets(396,5)
由此包中的文件引发的.
我的猜测是,由于环境不匹配,尝试使用VS 2017版本中的这些目标会产生错误,但我不知道如何追踪确切的问题.我可以看到v15还没有更新的包.
如何从MSBuild进行适用于VS 2017的T4变换?NuGet会有一个新的软件包在某个时候使用,还是不再支持?