t4

T4 Toolbox - Referencing Class in Current Assembly

末鹿安然 提交于 2019-12-04 00:17:57
I am writing a T4 script which reflects over certain classes and provides code generation based on them. The problem is that my script errors out, saying that the classes in my current project cannot be accessed. The script itself resides in the same assembly as the classes I am trying to reference. I've tried referencing the namespace, the file and adding a reference to the current assembly (the project itself) - all to no avail. What am I missing? Brian I believe this is what Nicko and uosɐſ are looking for. Just change the "MyAssembly.CodeGeneration" to the name of the project with the T4

T4 Template is Generating Extra New Lines on Some PCs

微笑、不失礼 提交于 2019-12-03 23:54:57
While using T4 classes for entity framework there are a couple of developers who generate classes with one extra new line for every line generated. I'm wondering if this is some kind of setting that needs to be changed so that their T4 generated files look like the generated files form other developers. As an example of what I am talking about: (removed specific names but you should be able to see the difference in the number of new lines generated from the same *.tt file.) ( Update: The issue occurs in other T4 Templates as well, not just EF. Both PCs are using TextTemplatingFileGenerator as

How to disable #line directives being written to the T4 generation output file

二次信任 提交于 2019-12-03 22:31:02
I have encountered a small problem with my T4 code generation. I have broken my T4 templates up into separate files and placed them in various directories, I have done this so parts of my code generation may be re-used in multiple projects, e.g. model generation, repository generation and service generation all include a core EntityGeneration.tt file. Unfortunately, when TextTemplating resolves my nested includes, it builds up a long #line pre-processor directive in its generated .cs file, combining all of the relative paths to the lowest level included file. Unfortunately, as this path is

how to generate a Custom Class via t4?

≯℡__Kan透↙ 提交于 2019-12-03 21:56:54
I am trying to generate the below code via T4. using System; using MyDAL; namspace Test { // Select... public partial class MyCustomer { public int id { get ;set;} public string name { get ;set;} public string surname { get ;set;} public MyCustomer() { } public List<Customer> GetById(int id) { // do something... } } // Delete,Update,Save public partial class MyCustomer { public bool Save(new MyCustomer) { // do something... } public bool delete(int id) { // do something... } public bool Update(int id) { // do something... } } } The T4 template I have so far: <#@ template language="C#"#> <#@

How to use a resx resource file in a T4 template

为君一笑 提交于 2019-12-03 20:31:39
问题 I cant figure out how to include the resource file (.resx) in the (.tt) T4 template. I tried so far... Importing the namespace <#@ import namespace="T4TemplateResources.resx" #> Also including the class 回答1: Nico's solution requires your solution to build. There is another way, without needing to compile your solution by reading the raw resx file. var fileName = "CustomResource.resx"; var filePath = Path.Combine(Path.GetDirectoryName(this.Host.ResolvePath("")), "WindowsFormsApplication1",

NEW T4 Controller Template in MVC3

我与影子孤独终老i 提交于 2019-12-03 15:23:56
As you know to create new t4 templates in MVC, need to add CodeTemplates folder to project. There are two main subfolders 1- AddController , 2- AddView I always use AddView folder to add new templates to generate custom views, know I need new template to generate controllers, but when I add new tt file to AddController folder, there is no any new option in templates of new controller, there is always 3 options: So how can I add new option to Add Controller window to use my custom Controller Template? Or if I try wrong way, what is your suggestion to use Template to generate controllers? It

How to trigger T4 template from PowerShell script

自闭症网瘾萝莉.ら 提交于 2019-12-03 14:02:06
In my VS2010 solution I have set of Powershell scripts and T4 templates based on T4Scaffolding NuGet, everything is working fine with scaffolding and related T4's, but in one of my scripts I need to trigger a T4 template located in another project. Any simple Powershel cmdlet for this? to just run the template with out passing any parameters or values. Thanks. It looks like you can just invoke their command line utility, so you could create a script that just takes the location of your .tt file. param([string] $T4Template) & "C:\Program Files (x86)\Common Files\microsoft shared\TextTemplating

Is there an EF6 DbContext Generator for C# which uses Fluent API?

这一生的挚爱 提交于 2019-12-03 09:20:03
I know that the EF6 VS Tools for Visual Studio 2012 come with a T4 template to generate DbContext classes which work with EF6. But I want to have a generator which uses fluent API. The older version I used with EF4 and EF5 don't work with EF6 and the author no longer works on them to make them EF6 compatible. Is anyone else working on a generator which uses Fluent API which works with EF6? http://visualstudiogallery.msdn.microsoft.com/72a60b14-1581-4b9b-89f2-846072eff19d If you have a database you can use reverse code first it will generate all your fluent api mapping. 来源: https:/

Debugging T4 Template in VS 2010 Crashes IDE

允我心安 提交于 2019-12-03 08:52:13
问题 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? 回答1

Reflection with T4 get assemblies

谁说我不能喝 提交于 2019-12-03 08:48:23
问题 I want to get all of class in the specific assembly this is my code var assembly=Assembly.GetExecutingAssembly(); var assemblies = assembly.GetTypes().Where(t => String.Equals(t.Namespace, "RepoLib.Rts.Web.Plugins.Profiler.Models", StringComparison.Ordinal)).ToArray(); when c# code all thing is ok and i get my assemblies but when write in t4 file i dont have any error but my assemblies count is. 回答1: In a T4 template the executing assembly is not yours but one from the T4 engine. To access