t4

T4 template adding assembly of existing project in solution

允我心安 提交于 2019-12-03 06:28:36
问题 Hi I need to add the assembly of an an existing project in my solution in my T4 Template file. The problem is that my T4 template is in a project called Project.WebApi and the class that I need in my T4 template is inside a project called Project.Common.WebApi. I have tryed importing the namespace like this: <#@ import namespace="Project.Common.WebApi.T4TemplateAttribute" #> But I get this error: The type or namespace name 'Project' could not be found (are you missing a using directive or an

T4 Get Current Working Directory of Solution

落花浮王杯 提交于 2019-12-03 05:04:25
问题 I am using T4 in Visual Studio 2010, and I want to iterate over the files in my solution, however I have found that T4 source generation works in a kind of a sandbox, and the current working directory is inside of the Visual Studio 10 directory in program files. Is there a way to reference the solution the T4 file is in relativistically, so that it doesn't break the build, or works on some one else's box that doesn't have the same file structure etc? Thanks 回答1: You must set the hostspecific

How can I use Linq in a T4 template?

断了今生、忘了曾经 提交于 2019-12-03 04:01:00
问题 I am using T4 to generate some screens and middle-tier code for a project, and would like to use Linq to simplify some of my template code. However, when I try to use Linq, the template reports a syntax error. 回答1: By default in Visual Studio 2008 (and as used in most online examples) the template is compiled with the 2.0 Framework, which does not include Linq. (See MSDN forum thread) To solve the problem, three steps are needed: In your template's language attribute, specify "C#v3.5" or

Code Generators or T4 Templates, are they really evil?

青春壹個敷衍的年華 提交于 2019-12-03 03:58:57
问题 I have heard people state that Code Generators and T4 templates should not be used. The logic behind that is that if you are generating code with a generator then there is a better more efficient way to build the code through generics and templating. While I slightly agree with this statement above, I have not really found effective ways to build templates that can say for instance instantiate themselves. In otherwords I can never do : return new T(); Additionally, if I want to generate code

Get Project or Relative Directory with T4

主宰稳场 提交于 2019-12-03 02:34:48
问题 How can I get a reference to the directory of the visual studio project or solution or the directory of the t4 template from within a t4 template? I have a template that concatenates a number of files together which are located relative to the template. I need to get a reference to there absolute location through a relative means. Hard coding an absolute path is not acceptable because the visual studio project will not always be in the same location and this would break the code generation.

Generated (by T4) file Build Action gets reset to Build

时光毁灭记忆、已成空白 提交于 2019-12-03 01:23:05
We have a database project in Visual Studio 2013. In this project we have a .tt file which generates .sql script. The problem is after generation the build action of the generated file is automatically set to Build. If we change it manually to None, it gets reset to Build after regenerating (running custom tool). Another strange thing is that it only happens if .tt file is in database project and in some folder of that project (not in root). if .tt file is in another project (anywhere) or in the root of the database project, the build action of the generated file does not change after

Using T4 Templates to Generate multiple classes based on POCO

佐手、 提交于 2019-12-03 00:43:53
Im looking for a way to increase productivity when I add a table to my database. Generally, when I add a new table I have to perform the following steps. Add table to the database (simple) Create the corresponding EF Code First class. (i dont use db migrations) Create a POCO model that matches the EF class created in #2. Create repository class Create Commands and Handlers for CQRS pattern Create AutoMapper maps for the newly created classes I recently created a new website where the requirements were to use EF Database first and I saw how it was using the tt files to generate the classes.

Debugging T4 Template in VS 2010 Crashes IDE

为君一笑 提交于 2019-12-02 22:48:11
I'm trying to debug a slightly-modified version of the ADO.NET POCO Entity Generator template using the directions Oleg Sych published a few years back. I modified the DbgJITDebugLaunchSetting key as recommended. I get a dialog indicating that a user-defined breakpoint has been hit. However, rather than being presented with the option to debug with a new instance of VS 2010, the original instance of VS 2010 just crashes and auto-restarts. Is it possible to debug T4 templates with VS 2010? in Visual Studio 2010 you need to call Debugger.Launch() before Debugger.Break(). Instead of using System

T4 template adding assembly of existing project in solution

和自甴很熟 提交于 2019-12-02 19:58:58
Hi I need to add the assembly of an an existing project in my solution in my T4 Template file. The problem is that my T4 template is in a project called Project.WebApi and the class that I need in my T4 template is inside a project called Project.Common.WebApi. I have tryed importing the namespace like this: <#@ import namespace="Project.Common.WebApi.T4TemplateAttribute" #> But I get this error: The type or namespace name 'Project' could not be found (are you missing a using directive or an assembly reference?) I have tryed adding the assembly like this: <#@ assembly name="Project.Common