t4

Can you use global variables inside a t4 template?

旧时模样 提交于 2019-12-04 11:20:50
How can I use global variables in a TT file? If I declare a variable in the header I get a compile error if I reference it in a function. <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <# int ValueForThisFile = 35; SomeFunction(); #> <#+ void SomeFunction() { #> public void GeneratedCode() { int value = <#=ValueForThisFile#>; } <#+ } #> I know that I could pass it as an argument but there are hundreds of calls and it would be syntactically tighter if I could avoid that. If this were one file I could hard code the value but there are dozens of

T4 vs CodeDom vs Oslo [closed]

点点圈 提交于 2019-12-04 11:04:35
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 7 years ago . In an application scaffolding project on which I'm working, I'm trying to decide whether to use Oslo , T4 or CodeDom for generating code. Our goals are to keep dependencies to a minimum and drive code generation for a domain driven

Switch from Entity Framework Database First to Code First

假装没事ソ 提交于 2019-12-04 10:03:19
Our Solution is currently based on Entity Framework Database First. We have a T4 Template that generates repository classes from the EDMX. We are reviewing our planned approach for releasing changes, especially Database changes. If we continue with Database first, then we will need to separately generate scripts to change the development and other databases. It seems that with Code First, we simply change the model and that generates scripts to change the various databases. This seems more straightforward, does not involve hand crafting scripting processes and lower risk. So, if we make the

T4 code generation without Visual Studio 2010?

瘦欲@ 提交于 2019-12-04 09:00:58
Is it possible to run T4 code generation without needing Visual Studio 2010? Basically I have to build an in house ORM (don't ask..if I had a choice I wouldn't). I was planning to use subsonic as a base but change some things and how they work. However my main question is can I run T4 from an external application that I write, so I can use the features of T4? Or am I better off doing it myself (which I doubt)? Michael Maddox TextTransform.exe will do what you want for simple scenarios: http://msdn.microsoft.com/en-us/library/bb126245.aspx Here is how to run a T4 template from your own code for

Using T4 Templates to Generate multiple classes based on POCO

笑着哭i 提交于 2019-12-04 08:44:47
问题 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

Running a T4 template using C#

∥☆過路亽.° 提交于 2019-12-04 08:05:48
问题 I have T4 template (mycode.tt) which generates a cs file. I usually right click the tt file and select RunCustomTool which internally takes an xml file and generate code for me. Now i want to run the custom tool using a c# windows application. So onclick of a button i want to run the Custom Tool . Is it possible to run the CustomTool from c#. Edit: I have 2 tt files and one of them doesn't have a codebehind cs file. But another has a .cs file attached with it and i am invoking the second file

Dynamically change data annotation in dynamic data project

[亡魂溺海] 提交于 2019-12-04 06:05:35
I have come across a scenerio that to customize DataAnnotations in Dynamic Data Web Application. This is the scenerio: [Display(Name="DispName")] public string DName{get;set;} Instead of hardcoding Name="DispName" for Display DataAnnotation, I want to fetch some value from DataBase and fit int the Name attribute. like: [Display(Name=SomeValueFromDB)] public string DName{get;set;} Is there any way to show the Name attribute of Display DataAnnotation from database instead of hardcoding its value? Also how can I change the ScaffoldColumn(True/false) based on table values? Can I do this using T4

what is and where can I find MvcTextTemplateHost

浪子不回头ぞ 提交于 2019-12-04 03:35:05
问题 I would like to know what this is MvcTextTemplateHost. I have this in my create.tt but I cant find it in my bin folder (searching with object viewer). I read up and found out it's in my VisualStudio.Extensions.web.dll but I cant find this dll I've read this T4 References for 'MvcTextTemplateHost' and 'VisualStudio'. I would just like to know what properties and methods this class has. I would love a t4 text editor. I installed a few but nothing gives me intellisense for this class thank you.

EF4: Get the linked column names from NavigationProperty of an EDMX

戏子无情 提交于 2019-12-04 02:39:51
I am generating POCOs (lets say they are subclasses of MyEntityObject ) by using a T4 template from an EDMX file. I have 3 entities, e.g.: MyTable1 (PrimaryKey: MyTable1ID) MyTable2 (PrimaryKey: MyTable2ID) MyTable3 (PrimaryKey: MyTable3ID) These entities have the following relations: MyTable1.MyTable1ID <=> MyTable2.MyTable1ID (MyTable1ID is the foreign key to MyTable1) MyTable2.MyTable2ID <=> MyTable3.MyTable2ID (MyTable2ID is the foreign key to MyTable2) Or in another view: MyTable1 <= MyTable2 <= MyTable3 I want to extract all foreign key relations NavigationProperty[] foreignKeys = entity

How to make connection strings available in a T4 template?

最后都变了- 提交于 2019-12-04 02:18:47
I've written a T4 template where I instantiate an EF context to read some data. The problem is that the context cannot see the connection string from the Web.config. How can I make the connection strings from the Web.config available to the template? More info: template is written from scratch EF edmx is located in another project the first query I make in the template tells me that it cannot find the required connection string in the project where the template resides Tried some of the solutions (thank you) below but I get this: Error 2 Compiling transformation: 'Microsoft.VisualStudio