t4

T4 Templates - suitable for generating C++ code?

萝らか妹 提交于 2019-11-30 04:02:11
问题 Are there any issues which might make MS's T4 Template code-generation system unsuitable for generating C++ code? 回答1: It can generate any text you want, including C++ code. 回答2: A bit lengthy answer yet I think some might find it interesting I would say T4 is excellent to generate C++ with Some might retort that C++ already has tools to do MetaProgramming with like: The Preprocessor Using the preprocessor and higher-order macros you can achieve somewhat what you can do with T4, but I say

How to use a dynamic connection string using a Model First approach but still use the data model in the EDMX?

隐身守侯 提交于 2019-11-30 04:01:22
I have created an EDMX using EF 5 with the Model First approach, i.e. I started with a blank designer and modeled my entities. Now I want to be able to use this model defined in the EDMX but supply runtime SQL Server connection strings without modyfing the config file. I know how to pass a connection string to the DbContext but the issue is locating the metadata for the mappings within the assembly. For example, my EDMX has this connection string in the app.config <add name="MesSystemEntities" connectionString="metadata=res://*/Data.DataContext.EntityFramework.MesSystem.csdl|res://*/Data

Text Transformations & Finding Entity Plural (Collection)

心已入冬 提交于 2019-11-30 03:41:19
If I have a .tt template, I can use entity.Name to write out the name of an entity, e.g: foreach (EntityType entity in ItemCollection.GetItems<EntityType>().OrderBy(e => e.Name)) {; WriteLine(entity.Name); } Using normal transformations or T4, How do I write out the actual name of the entity set? (E.g. for Person, it might be Persons - but maybe I changed it to People in the designer, so I'd want that instead). Thanks! Richard Dave I was looking for the answer to the same question and found that it's not too bad. However, instead of getting the EntitySet name, it's quite easy to use the same

Generate Enum from Values present in a table using ADO.NET Entity framework

断了今生、忘了曾经 提交于 2019-11-30 03:15:07
问题 My requirement is to create an Enum based on values present in a table from DB. I am using ADO.NET Entity Framework model (.edmx file), Can any one of you help me out. 回答1: It is probably a lot easier to use T4 templates. Here is a really good article on getting started My example below uses a direct SQL Connection, but as you can see you can include any code and generate whatever output you like into a cs file that is compiled into your project. You could replace the ADO syntax below with an

How can I resolve this error: Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string

家住魔仙堡 提交于 2019-11-30 02:57:20
How can I resolve these errors: Loading the include file 'EF.Utility.CS.ttinclude' returned a null or empty string. Value does not fall within the expected range. Tools Used: VS 2012, Entity Framework 5.0.0, T4MVCExtensions 3.5.0, .NET Framework 4.5 I've been using EF and T4 templates in a project within a large MVC solution without incident. Now, when I right-click on the edmx diagram, EF responds with the message: Value does not fall within the expected range. When I compile the EF project it responds with these messages: Loading the include file 'EF.Utility.CS.ttinclude' returned a null or

How to output namespace in T4 templates?

邮差的信 提交于 2019-11-30 01:27:01
I have a T4 template for a class set up with TextTemplatingFileGenerator Custom Tool in Visual Studio: <#@ template language="C#v3.5" hostspecific="True" debug="True" #> <# var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile); var namespaceName = "MyNamespace"; #> namespace <#= namespaceName #> { public static class <#= className #> { // some generated code } } How can I get the value of the "Custom Tool Namespace" property in Visual Studio, so I don't have to hardcode the namespace? I would even be happy with the default namespace for the C# project. If you're using

T4MVC Error - T4 file is blocked or in a non trusted zone

梦想的初衷 提交于 2019-11-30 00:09:40
I am running Visual Studio 2010 on a Windows 7 virtual machine inside of Parallels Desktop 8 on a Mac Book Pro. I'm trying to incorporate T4MVC into a new MVC4 project. I installed the T4MVC package from Nuget and immediately started getting this error... Failed to resolve include text for file:The path '\psf\Home...\T4MVC.tt.hooks.t4' must be either local to this computer or part of your trusted zone. If you have downloaded this template, you may need to 'Unblock' it using the properties page for the template file in Windows Explorer. I went into the "Properties" menu for the T4MVC.tt.hooks

How do I pass a string parameter to a t4 template

北慕城南 提交于 2019-11-29 23:13:36
Hi I am trying to find a way to pass a normal string as a parameter to a text template. This is my Template code, if someone could tell me what I would need to write in c# to pass my parameters and create the class file. That would be very helpful, Thanks. <#@ template debug="false" hostspecific="true" language="C#" #> <#@ output extension=".cs" #> <#@ assembly name="System.Xml" #> <#@ assembly name="EnvDTE" #> <#@ import namespace="System.Xml" #> <#@ import namespace="System.Collections.Generic" #> <#@ parameter name="namespacename" type="System.String" #> <#@ parameter name="classname" type=

How not to output default T4 generated file?

末鹿安然 提交于 2019-11-29 16:02:30
问题 I am using T4toolbox to generate a bunch of files, let's say my t4 file name is x.t4, but default it generate a x.txt, which has nothing inside, can I tell t4 engine not to do this? 回答1: Found a trick/hack! <#@ output extension="/" #> or <#@ output extension="\\" #> Visual Studio neither outputs the default file nor complains about its inability too much. If you want to avoid warnings, you can also modify output path through the extension: <#@ output extension="xml/../_" #> The file will

How can I customize WCF client code generation?

女生的网名这么多〃 提交于 2019-11-29 15:28:56
问题 Are there any tools or code generation templates that will let me customize and extend the WCF cliend proxies? It's not that svcutil is horribly broken, but rather I'd like to be able to generatate additional code based on the service contract, not just be limited the svcutil output. 回答1: Have you looked at the Web Service Software Factory? It allows you to have complete control over the generation of proxy code. 回答2: I've since found two other options: wscf.blue WCF Proxy Genererator 回答3: