t4

Getting the CodeClass from argument inside CodeAttribute?

青春壹個敷衍的年華 提交于 2019-12-10 19:26:58
问题 I am working on some T4 code generation, for this I need the CodeClass of the type that is passed inside the constructor of BarAttribute. class Baz { } class Bar : Attribute { public Bar (Type type) { } } [Bar(typeof(Baz))] public class Foo { } This is what I have so far inside my T4 Template, I just give the CodeAttribute '[Bar(typeof(Baz))]' to the function: private CodeClass GetType(CodeElement codeElement) { CodeAttribute attribute = (CodeAttribute)codeElement; if (attribute.Name == "Bar"

Customize the DbContext Generator

为君一笑 提交于 2019-12-10 16:58:15
问题 For a database first design, creating the EDMX generates the DbContext and the poco model T4 (.tt) template files. I am successfully able to customize the Model.tt file to make it generate POCO classes with Pascal cased class names and property names and also the poco class file names in Pascal case which fits beter with with the coding standards of the rest of my code. The issue I am trying to tackle is, I have to edit the Model.tt files for every EDMX when I create one, rather I am trying

How to include a custom utility class with our T4 templates generators?

ぐ巨炮叔叔 提交于 2019-12-10 16:57:35
问题 How to include a custom utility class with our T4 templates generators ? I tried adding a module to the project but it seem there is no way to include it for my generators to use the methods from it. Thanks. 回答1: You cannot access any code that is in your project, from your template. Even if you could, how would it execute? The template is executed at design time. Use the Inherits directive, give the name of your utility class. http://technet.microsoft.com/en-us/query/bb126474 See 'Using a

Using SSDT as source for T4 templates

二次信任 提交于 2019-12-10 16:24:38
问题 I have a SQL Server Data Tools (SSDT) project that has a number of stored procedures for which I would like to generate the C# code to call them using T4. Are there any existing examples for doing this? So far, I can create a function per proc, but I'd really like to be able to tap into the meta data SSDT creates so I can get the parameters, data types, and return values from it rather than doing string parsing. 回答1: COOL WITH A CAPITAL C! (but don't tell anyone who uses an ORM!) To get the

What is the '.tt' extension?

时间秒杀一切 提交于 2019-12-10 15:55:30
问题 I work with a bunch of something.js.tt JavaScript files using Knockout and a bunch of something-else.tt HTML files. The infrastructure is mostly a C backend with Perl serving API and we use these .tt files to show the HTML and .js.tt to serve the Knockout.js code. What is .tt ? 回答1: A TT file is a Visual Studio Text Template, developed by Microsoft. 回答2: Text Template Transformation Toolkit, shortly written as T4, uses the .tt file extension for its source files. It is Microsoft's template

Generating T4 on Build using VS 2012

自作多情 提交于 2019-12-10 14:38:34
问题 I am trying to generate code on every build of my project using VS2012. I have 3 projects in my solution : project 1 has some classes project 2 has the generic template project 3 has the template that read a json file and then call the generic template form project 2 to generate its file. When I am clicking on Build/Transform All T4 Templates, there is no problem, the generation goes well. But I am trying to configure my build to include this step automatically on every build. I have added

T4 Template in VS 2015

℡╲_俬逩灬. 提交于 2019-12-10 13:47:40
问题 How do I get T4 Template support in Visual Studio 2015 ? In VS 2015 the file property does not allow to specify the *tt file to be marked and allow to run from context menu. I am using VS 2015 CTP6. 回答1: Tried VS2015 Ultimate CTP6 and T4 support is in (as well as debugging T4 which is nice). One specify TextTemplatingFileGenerator as Custom tool as before and when saving the .TT file it is executed. There's a context menu called "Run Custom Tool" which seems to execute the .TT file as well.

Is there a way to avoid using hard-coded resw keys with the windows store app ResourceLoader?

我是研究僧i 提交于 2019-12-10 12:27:02
问题 Is there a way to avoid using hard-coded keys for the globalized strings contained in the resw file within a windows store app? i.e. // I have to use a hard-coded string key, which may violate the // DRY principle to gain access to the translation from C#: var translation = Windows.ApplicationModel.Resources.ResourceLoader.GetString("MyStringKey/Text") 回答1: You can use the T4 template below to automatically generate a C# wrapper around your resw file. This means you have no need to litter

Generating more than one output file from a template

倾然丶 夕夏残阳落幕 提交于 2019-12-10 11:17:38
问题 Hi I am writing a custom template generator for my xml file. I was wondering if you guys can tell me a way I can generate more than one output file from the template under the same template. The no of file should depend on the no of xml files I input If I want to generate the c# class for a.xml I am doing something like this <#= XmlToCsGenerator.Xml(this.Host.ResolvePath("a.xml")) #> where my function XmlToCsGenerator.Xml(string path) returns the string to be written into the file. Thanks in

Can you add custom T4 Templates to the VS2008 “Add New Item” dialog?

帅比萌擦擦* 提交于 2019-12-10 10:29:55
问题 I have created a set of templates that I want to share across multiple projects. Is it possible to add the template to the Project “Add New Item” dialog such that when I choose it an instance of the code file is generated from the template and added to the project? Update Thanks for suggestions Preet. That answers the question but I think I have asked the wrong one. Thinking about it some more, I now want to be able automate the processing of T4 templates and pass parameters to them from user