t4

T4 code generation during build, custom assembly reference

我怕爱的太早我们不能终老 提交于 2019-12-05 03:47:37
I have a T4 template that processes several .tt files in my project. I also have some custom classes I've defined to help with the code transformation process. <#@ template language="C#" hostspecific="True" debug="True" #> <#@ output extension="cs" #> <#@ assembly name="System.Core.dll" #> <#@ assembly name="$(TargetDir)\MyDependency.dll" #> This works in Visual Studio, I have a VS Macro which defines $(TargetDir) correctly. Now, I want to perform the code generation process during my build process. I added: <TransformOnBuild>true</TransformOnBuild> <OverwriteReadOnlyOutputFiles>true<

Getting the Schema from an EDMX file

风流意气都作罢 提交于 2019-12-05 02:09:07
问题 I need to modify the T4 template POCO.tt to retrieve the database schema from the EDMX file. I can see the schema stored in an EntitySet tag in the XML. However I cannot find the schema anywhere when using an EntitySet object. Anyone know where I would find the database schema? Thanks 回答1: UPDATE I wrote up my findings on this in a blog post: http://www.ninjanye.co.uk/2011/06/getting-schema-information-from-edmx.html http://jnye.co/Posts/3/getting-schema-information-from-an-edmx-file-with

T4 append output to existing file

谁说我不能喝 提交于 2019-12-05 01:16:25
Is it possible to make a T4 template output to be merged with an existing file? For example, if a T4 template generates localization resource XML files, is it possible to merge them in some existing resource file? You can get access to the underlying string builder the the T4 uses thought the GenerationEnvironment property. So by adding something like the following to your T4 you should be able to get a workable solution; <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".txt" #> <#@ Import Namespace="System.IO" #> Line #<#= rand.Next(0, 100).ToString() #>

How to trigger T4 template from PowerShell script

别来无恙 提交于 2019-12-04 19:37:35
问题 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. 回答1: It looks like you can just invoke their command line utility, so you could create a script that just takes the location of your

How to set Build Action for generated files from a T4?

馋奶兔 提交于 2019-12-04 16:49:42
The question is: is there a way to have a setting in the *.tt file so that the generated files are set to a specified Build Action? The thing is I am generating SQL script using a template. I use this script as pre-deploy script in Database project. Currently, I have to manually set the Build Action to Pre-Deploy every time a file being re-generated - I would like to automate it. Both files - template and SQL that it generates - are included into project. In Project (*.sqlproj) they are as next tags: <PreDeploy Include="Migration\PreDeployScript.sql"> <DependentUpon>Migration\PreDeployScript

Analyze 64-bit DLL from within T4 template in Visual Studio (32-bit) using Reflection

怎甘沉沦 提交于 2019-12-04 16:46:27
I would like to analyse a DLL from within a T4 template using Reflection, so that I can generate code based on the results of the reflection analysis. I know EnvDTE would be a better option, but this is not possible in my case for several reasons. The problem with reflection is that the DLL is a 64-bit DLL and if I load that within the T4 template I get a BadImageFormatException because I am trying to load a 64-bit DLL into a 32-bit process (Visual Studio 2012). Is there any way to analyse the contents of that DLL within T4, preferrably using reflection? I have already thought about writing a

How do I adapt the Entity Framework POCO T4 template to create classes in a separate project?

旧时模样 提交于 2019-12-04 15:51:32
I like to to keep my code first - or T4 generated - POCOs in a project separated from the DbContext. This helps me ensure my entity classes aren't coupled to any one data access service. When I create a new DB first EDMX model, the wizard generates a T4 template to generate all the POCOs in the same project as the DbContext. How can I modify this template to add classes to a separate project? On closer inspection, it would probably be much easier to move the DbContext to a new project, but the T4 for this has no call to fileManager.StartNewFile so i don't know where to begin telling it to

T4 Template is Generating Extra New Lines on Some PCs

半世苍凉 提交于 2019-12-04 15:37:29
问题 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

Entity Framework Database First POCO t4 generation and validation

一个人想着一个人 提交于 2019-12-04 12:45:48
NOTE: I am using ASP.Net application and not MVC [so no validation attribute are supported] I used Database First approach and then generated my POCO classes using the POCO t4 template. I moved the generated POCO classes in it's own library (Domain.Model). Now I want to inject validation to the POCO class using Enterprise Library 5. How can I do that. I don't want to perform validation in UI, but want to add the validation attributes using Enterprise Library to the POCO class without modifying the generated POCO class. If I modify it, then whenever I generate new classes, I will loose all my

How to deploy T4 include files with NuGet package

会有一股神秘感。 提交于 2019-12-04 11:55:22
I have some T4 include files which I want to reuse in several projects. So I have created a NuGet package and placed the files in the Tools folder of the package. Now they are installed in the packages\PackageName.x.x.x\Tools folder and I can add an include directive in my T4 files in the project. But the disadvantage of this is, that there is a version number in the path which will change when I create new versions of the package. That would require me to update all include directives in the project. Does anybody know a hint for a good approach for this? If these T4 templates are supposed to