t4

Cannot get T4MVC to work with VS2010 and ASP.NET MVC 2

萝らか妹 提交于 2019-12-29 06:52:10
问题 I'm trying to add the T4MVC templates to my project, but I'm experiencing some problems. I went to Codeplex and downloaded the latest version of T4MVC, and according to the instructions I just copied the two files T4MVC.tt and T4MVC.Settings.t4 into the root of my web application. Immediately, I got the following errors: From T4MVC.cs (generated file): A namespace cannot directly contain members such as fields or methods From T4MVC.tt (the code generating template): Compiling transformation:

Are there any limitations on what libraries can be imported in a t4 template?

时间秒杀一切 提交于 2019-12-25 01:28:47
问题 We're trying to learn to use T4 Templates. I have a desire to use the System.Data.Entity.Design.PluralizationServices library in order to better pluralize some Entity Model names within my template, but I've come across some issues in the achievement of this goal. Running code to generate output text. I think this is possible, but if it's not going to work, then there's no need to go any further. (I could call Date.Now.ToString() and get the expected result. I haven't tried anything much more

T4 - Error 60: A field initializer cannot reference the non-static field, method, or property

两盒软妹~` 提交于 2019-12-24 23:24:24
问题 I try to use the solution from Microsoft documentation. At the beginning of my .tt file I put: <#@ template language="C#" hostSpecific="True" #> <#@ output extension="cs" #> <#@ import namespace="System.IO" #> Then I try to get some variables from my previosly transformed file: <#+ string myFile = File.ReadAllText(Host.ResolvePath("AssemblyInfo1.cs")); #> In the line above I get error. If the line is commented everything is OK. Error output is: Error 60: A field initializer cannot reference

How to access custom project properties from a T4 template?

此生再无相见时 提交于 2019-12-24 17:21:58
问题 In VS 2010, is it possible to access a custom project property from a T4 template, e.g. in an Assembly directive? I can't manage to access such properties, e.g. defined in a <PropertyGroup> in my .csproj file. Accessing predefined VS macros (like $(SolutionDir) or $(ConfigurationName) ) works though. Thanks and best regards, Oliver 回答1: I solved the problem by creating a file containing the Assembly directive as a pre-build step (which can access the environment variables). In all my T4

Entity Framework TT template -> Navigation Property name based on foreign key ID

故事扮演 提交于 2019-12-24 11:13:31
问题 I have the following table: CREATE TABLE Phone( PhoneId INT IDENTITY (1, 1) NOT NULL, CONSTRAINT PK_Phone PRIMARY KEY CLUSTERED (PhoneId ASC)) CREATE TABLE Person( PersonId INT IDENTITY (1, 1) NOT NULL, MobilePhoneId INT NOT NULL, PhoneId INT NOT NULL, ... CONSTRAINT PK_Person PRIMARY KEY CLUSTERED (PersonId ASC), CONSTRAINT FK_Projects_Phone FOREIGN KEY (PhoneId) REFERENCES Phone(PhoneId), CONSTRAINT FK_Projects_MobileId FOREIGN KEY (MobilePhoneId) REFERENCES Phone(PhoneId), ... I am using

T4 References for 'MvcTextTemplateHost' and 'VisualStudio'

本小妞迷上赌 提交于 2019-12-24 08:58:24
问题 I'm having problems creating MVC 3 T4 template. I have cleared the "Custom Tool" property for the template as MvcTextTemplateHost not found suggests. But I cant find which reference to include. Also I need to find reference for Microsoft.VisualStudio.Web.Mvc.Scaffolding.BuiltIn, I cant find it in the list of references. Which references are missing? TIA /Lasse 回答1: Probably the simplest way to go about this is to add the existing code templates to your project with NuGet (install-package

t4 templates per template TransformOnBuild setting

你离开我真会死。 提交于 2019-12-24 03:50:18
问题 I would like to automatically execute one of the .tt files when my project is built, but not the others. Is it possible to set the TransformOnBuild property on specific .tt files instead of project wide? Or another method to accomplish this? 回答1: I have decided to add a custom pre build step to generate the .tt files needed: <Exec Command=""%PROGRAMFILES(x86)%\Common Files\microsoft shared\TextTemplating\10.0\TextTransform.exe" template.tt -out template.cs" /> This method also allowed me to

Web.tt in VS 2013 MVC project causes error “value does not fall within the expected range”

狂风中的少年 提交于 2019-12-23 14:24:17
问题 Has anyone else encountered this in VS 2013? Any way of fixing? Create a new asp.net web application with visual studio 2013. Under "Add folders and core references for:", check MVC. Click OK. Open the web.config and copy the contents. Add a new text template to your project called "Web.tt" Paste in the contents of your web.config and change the output extension to be .config. all you need is this line (and then your web.config contents after it): <#@ output extension=".config" #> Make sure

SubSonic 3.0.0.2 Structs.tt

﹥>﹥吖頭↗ 提交于 2019-12-23 12:23:44
问题 The error I'm getting seems to be coming out of the Structs.tt file. I'm using the Northwind db and only using the Products table (I excluded all other tables). I return Json(Product.All()). Here's the error: A circular reference was detected while serializing an object of type 'SubSonic.Schema.DatabaseColumn'.Here's the Stack Trace: System.InvalidOperationException was unhandled by user code Message="A circular reference was detected while serializing an object of type 'SubSonic.Schema

Where are the built in MVC scaffolding T4 templates?

可紊 提交于 2019-12-22 18:42:59
问题 With the newest MVC tools, when I add a controller, I get scaffolding for the controller code as well as the CRUD Views. I'm not asking about how to override templates. I understand that I can override the T4 scaffolding templates, but I would like to see the existing built-in scaffolding templates that support the default code generation. Where can I find the T4 code that supports the built-in/default scaffolding for MVC Views and Controllers? 回答1: Per Hansleman: C:\Program Files (or x86)