t4

How to make connection strings available in a T4 template?

别来无恙 提交于 2020-01-12 07:04:04
问题 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

How to make connection strings available in a T4 template?

人盡茶涼 提交于 2020-01-12 07:04:02
问题 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

Cannot reference dependency assemblies in T4 template when using TransformOnBuild

試著忘記壹切 提交于 2020-01-11 06:59:09
问题 We're trying to use T4 with Visual Studio 2010 (SP1) to build scripts for another language that are based upon some of our existing C# classes. I'm hoping for the following: The template needs to load our existing assembly and use objects from a namespace in that assembly. The transformation needs to run on every build on every development machine and build server without any additional installations. (1) and (2) need to work together. (1) was fairly straightforward: <#@ assembly name="$

How can set the `custom tool` property of an xml file to a T4 file?

心已入冬 提交于 2020-01-11 06:38:05
问题 we know that asp.net .resx files have an custom tool for generating some c# code ( ResXFileCodeGenerator ). I have an xml file and I want to set the custom tool property of that to a T4 file. how can i bind T4 file to the xml file? 回答1: You can do that with T4 Toolbox. Select the resx file in Solution Explorer and set the Custom Tool Template in the Properties window. 回答2: Have a look at http://t4-editor.tangible-engineering.com/t4editor_features.html#Compare. There's a feature called "Add

Getting the namespace for an edmx in a T4 template

蓝咒 提交于 2020-01-07 05:29:11
问题 When I install my template into a different namespace than the edmx's namespace the code that is generated has errors because of the missing namespace. So I'm trying to add a "using" statement to solve this problem, but I don't know how to get the namespace the edmx is in. I have this so far (edited for brevity): <#@ template debug="true" hostspecific="true" language="C#" #> <#@ include file="EF.Utility.CS.ttinclude"#> <#@ output extension=".cs"#> const string edmxFile = @"../Entities

How do I automatically add interfaces to EF database first generated entities that have specific properties (column names) by editing T4 .tt templates

折月煮酒 提交于 2020-01-06 19:27:29
问题 I have a around 50 databases that have 150 tables each and working on a search mechanism that would allow to query the tables that have specific columns. Most database structures are same so idea is to generate EF entities and put interfaces behind the entities generated if tables that they are being generated from have specific columns, so that I could later query then on that column. Model will likely be constantly changing so I can't manually add interfaces on tables - here come in T4

TextTransform on MSBuild only when file modified? (or an alternate route of doing this)

无人久伴 提交于 2020-01-05 13:09:31
问题 I have a project that integrates TextTransform with MSBuild, but I am now at the point that the files are too many and it is slowing down development time. The process that I have is, I have a POCO.cs; I use Roslyn to Parse the .cs file to gather some metadata; hand the metadata to a .tt file that will then generate a [Implementation].cs Here is part of the .csproj file that pertains to my question: <PropertyGroup> <_CommonProgramFiles>$([System.Environment]::GetEnvironmentVariable(

TextTransform on MSBuild only when file modified? (or an alternate route of doing this)

南楼画角 提交于 2020-01-05 13:08:59
问题 I have a project that integrates TextTransform with MSBuild, but I am now at the point that the files are too many and it is slowing down development time. The process that I have is, I have a POCO.cs; I use Roslyn to Parse the .cs file to gather some metadata; hand the metadata to a .tt file that will then generate a [Implementation].cs Here is part of the .csproj file that pertains to my question: <PropertyGroup> <_CommonProgramFiles>$([System.Environment]::GetEnvironmentVariable(

Cannot use T4 templates inside a .NET Core project

柔情痞子 提交于 2020-01-04 05:50:27
问题 I have a .NET Core class library project and I want to use design-time T4 templates. The tempalate compiles correctly, but when I try to use Reflection it raises an error Running transformation: System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. File name: 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken

Xamarin Studio / MonoDevelop T4 pre-build

拥有回忆 提交于 2020-01-04 02:44:47
问题 Is there a way, with Xamarin Studio, to have a pre build command that runs a T4 template? This would help generating a C# file on the fly. 回答1: Ok here is the solution if somebody is interested: Just create a mono-t4 file in your solution folder: #!/bin/bash mono /Applications/Xamarin\ Studio.app/Contents/MacOS/lib/monodevelop/AddIns/MonoDevelop.TextTemplating/TextTransform.exe -o $1 $2 Don't forget to make it executable with chmod +x mono-t4 Then in your project options, in "Custom commands"