t4

T4 reports Compiling transformation: Invalid token 'this' in class, struct

♀尐吖头ヾ 提交于 2020-02-01 10:56:50
问题 Attempting to run the T4 templates for Immutable Object Graph gives errors of ╔═══════╦═══╦══════════════════════════════════════════════════════════════════════════════════════════════════╦═════════════════════════════════════════════════════════╦═══╦════╦══════╗ ║ 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

T4 reports Compiling transformation: Invalid token 'this' in class, struct

走远了吗. 提交于 2020-02-01 10:56:49
问题 Attempting to run the T4 templates for Immutable Object Graph gives errors of ╔═══════╦═══╦══════════════════════════════════════════════════════════════════════════════════════════════════╦═════════════════════════════════════════════════════════╦═══╦════╦══════╗ ║ 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

Can I use T4 programmatically from C#?

流过昼夜 提交于 2020-01-28 04:46:32
问题 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? 回答1: 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. 回答2: A simple way to do this:

T4 Template TransformText method XML Documentation

回眸只為那壹抹淺笑 提交于 2020-01-24 21:22:04
问题 We have several projects that use runtime T4 Templates. The T4 Template files (.tt) produce generated .cs files with the same name. These contain a TransformText() method and a ToStringHelper() method which do not contain XML comments. We generate XML documentation for all of our projects, so the lack of it on these two methods causes persistent warnings during compilation. My question is, does anyone know how to get these two generated methods to have XML documentation? Thanks for any

SubSonic 3 and multiple PK columns

冷暖自知 提交于 2020-01-20 08:50:07
问题 I'm having problem with SubSonic 3 and multiple Primary Key columns. It seems like it isn't supported via the ActiveRecord T4 script. In line 173 of Settings.ttinclude return this.Columns.SingleOrDefault(x=>x.IsPK) ?? this.Columns[0]; It tries to get a Single Primary Key Column and failed. Any solutions? 回答1: Many ORM products do not support composite keys due to the overwhelming complexity of doing so. As far as I know, NHibernate is the only well-known .Net ORM product that does. Mindscape

How to use DbContext in T4 template?

五迷三道 提交于 2020-01-13 18:54:11
问题 I want to generate some code with a T4 Template using EntityFramework. I created a T4 Template in the same Assembly as my currently working EF6 DbContext: <#@ template language="C#" hostspecific="true" debug="True" #> <#@ assembly name="$(SolutionDir)\packages\EntityFramework.6.1.3\lib\net45\EntityFramework.dll" #> <#@ assembly name="$(TargetPath)" #> <#@ import namespace="Conwell.Administration.Data.Entities" #> <# using (var db = new KassenautomatEntities()) { #> //Hello World <# } #> When

C# T4 Template equivalent for “extern alias”

陌路散爱 提交于 2020-01-13 14:16:28
问题 I'm looking for a way to make use of an assembly referenced by the project with an alias (i.e. other than global) from a runtime T4 template. My goal is to be able to reference a namespace, with all its content obviously, from that assembly: <#@ import namespace="CustomAlias::Target.Namespace" #> Basically, I'm looking for the equivalent of writing something like: extern alias CustomAlias; using CustomAlias::Target.Namespace; I've attempted searching, here and Google, and the only mention

Entity Framework 5 stopped running T4 templates files on save

北城余情 提交于 2020-01-13 12:08:31
问题 At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it: EntityContainer.Context.tt which contains the generated DbContext object and EntityContainer.tt which contains the entities themselves. For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files

Entity Framework 5 stopped running T4 templates files on save

亡梦爱人 提交于 2020-01-13 12:08:13
问题 At work we just upgraded to Entity Framework 5. Our EDMX file now has a couple other nodes beneath it: EntityContainer.Context.tt which contains the generated DbContext object and EntityContainer.tt which contains the entities themselves. For a short period, adding an entity in EF was automatically regenerating the tt (T4 Templates) when we would save the EDMX file. Now all of a sudden we have to right-click the T4 templates and select "Run Custom Tool" to get them to regenerate the .cs files

How to make connection strings available in a T4 template?

て烟熏妆下的殇ゞ 提交于 2020-01-12 07:05:33
问题 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