t4

How to use T4 code generation templates with VS C++ projects?

生来就可爱ヽ(ⅴ<●) 提交于 2019-11-29 01:33:16
问题 T4 template files are automatically recognizable by the IDE under C# projects, but I have no clue on how they can be integrated into C++ projects (other than using make files). Any ideas? 回答1: T4 Template files can be integrated into C++ projects, but it's a bit more work than with a C#/VB project. Create a new text file in your C++ project and give it a .tt extension. Then write your template as normal. A C++ project then needs further work to get it to transform the templates. The quick and

Can I use T4 programmatically from C#?

為{幸葍}努か 提交于 2019-11-28 23:19:56
I am writing software that produces C# code. Mostly I am using StringTemplate and StringBuilder. Is there any way to use T4 templates direct from my code? Oleg Sych describes how to do this here: Understanding T4: Preprocessed Text Templates . Note that it looks like you'll need Visual Studio 2010 to generate a preprocessed Text Template, but you'll be able to host the preprocessed Text Template wherever you like - including within your WinForms application. A simple way to do this: System.Diagnostics.Process proc = new System.Diagnostics.Process(); proc.EnableRaisingEvents = false; // Set

Determine solution configuration (debug/release) when running a T4 template

自古美人都是妖i 提交于 2019-11-28 22:55:12
I have a T4 template that can output either optimized content or standard content based on a flag. Currently I'm manually changing the flag based on my needs. What I'd love to do is set the flag based on the Configuration of the Solution in Visual Studio. If set to build in Debug mode, I would output standard content. If set to build in Release mode, I would optimize the content instead. I found another T4 question that looks promising: T4 Text Template - Is it possible to get compilation symbols from host? However, in my case I would want to do something like the following: <#@ template

How to output namespace in T4 templates?

大城市里の小女人 提交于 2019-11-28 22:15:37
问题 I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio: <#@ template language="C#v3.5" hostspecific="True" debug="True" #> <# var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile); var namespaceName = "MyNamespace"; #> namespace <#= namespaceName #> { public static class <#= className #> { // some generated code } } How can I get the value of the "Custom Tool Namespace" property in Visual Studio, so I don't have to

Using types in a T4 template that exist in the same project as the template

爷,独闯天下 提交于 2019-11-28 21:54:47
问题 I'm working on my first T4 code generation tool to add some Stored Procedure helper code to my project. I've created custom types (e.g. StoredProcedure and StoredProcedureParameter to help with my code generation and have included the assembly and namespace references in my code: <#@ template debug="false" hostspecific="false" language="VB" #> <#@ output extension=".generated.vb" #> <#@ assembly name="$(TargetPath)" #> <#@ import namespace="StoredProcCodeGenerator" #> This allows me to use my

Design Time Reflection

旧时模样 提交于 2019-11-28 18:27:44
Is there a way to do reflection pre-compile - at design time? My intent is to use T4 to spit out custom codes based on classes that implement certain interfaces. I know I can call upon reflection, but I want the T4 script to spit out the additional code before compile, otherwise I will need to compile the code twice, once to generate dlls, twice to let T4 reflect on the previously generated dll and add additional scaffolding. Is there a way to do reflection at design time? Is there a better way to do this? There actually is a way of generating code pre-build based on the CodeModel provided by

Change Default MsTest Unit Test Wizard Template

旧时模样 提交于 2019-11-28 10:26:43
My team is using the unit test wizard, but has found the amount of cruft generated annoying. Is there anyway to modify this template? Thanks Yes, you can, on several levels: Project Template You can get rid of the "About Test Projects" and other files using the Options menu in Visual Studio. Go to Test Tools -> Test Project and unselect the options you don't want. If that is not enough, you can find the project template in a folder similar to this: C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\CSharp\Test\1033 Your path may differ slightly if you run on 32-bit

Cannot find Microsoft.VisualStudio.TextTemplating assembly

本小妞迷上赌 提交于 2019-11-28 09:37:30
I am doing some work with T4 (Text Template Transformation Toolkit) and am trying to get to a point where I can create my own custom text template host. However, all of that relies on the Microsoft.VisualStudio.TextTemplating assembly and I cannot find it on my system! I first tried adding a reference to the assembly in Visual Studio, but the assembly for Microsoft.VisualStudio.TextTemplating is not listed under the .NET tab. I then took a look in the %WINDIR%/Assembly directory and found an entry for Microsoft.VisualStudio.TextTemplating . However, when I try and browse to this location and

MSBuild support for T4 templates in Visual Studio 2017 RTM

孤者浪人 提交于 2019-11-28 09:06:57
In Visual Studio 2015, I'm using the NuGet package Unofficial.Microsoft.VisualStudio.TextTemplating.14.0.0 which allows me to transform T4 templates directly from MSBuild, whenever a project is built. In Visual Studio 2017 RTM however, this breaks the build with the following messages: 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.

T4 templates error: loading the include file ef.utility.cs.ttinclude returned a null or empty string

浪尽此生 提交于 2019-11-28 08:26:50
I have overridden the controller generation T4 templates ( ControllerWithContext.tt ) as described here . I would like to take advantage of the code helper utilities found in EF.utility.CS.ttinclude as used in the POCO model generator T4 template. Therefore I copied the following lines from my Model.tt to my ControllerWithContext.tt . <#@ include file="EF.Utility.CS.ttinclude"#> However, when I try to add a controller I am getting the error message Loading the include file 'EF.utility.CS.ttinclude' returned a null or empty string According to the MSDN documentation , this error is because the