t4

MVC 4 custom data annotations read in T4 scaffolding

坚强是说给别人听的谎言 提交于 2019-12-08 09:01:10
问题 Can you create custom data annotations for the model that can be read inside the T4 template for the View like property.Scaffold is read? I would like to add data annotation parameters like Scaffold based on which I would build the view. Thank you 回答1: I wrote a blog post on the solution I came up with for MVC5. I'm posting it here for anyone who comes along: https://johniekarr.wordpress.com/2015/05/16/mvc-5-t4-templates-and-view-model-property-attributes/ Edit: In your entities, decorate

Accessing Custom Attributes in a T4 Template (VS2012 MVC4)

走远了吗. 提交于 2019-12-08 02:41:21
问题 I'm trying to access my custom attributes like SortableAttribute attached to my model properties in a T4 Controller template I'm writing. I've copied the class block, assemblies and imports from List.tt as boilerplate. First I tried to cast the attributes as follows: <#+ string SortableBy(PropertyInfo property) { foreach (object attribute in property.GetCustomAttributes(true)) { var sortable = attribute as SortableAttribute; if (sortable != null) return sortable.By == "" ? property.Name :

Generate entity class from database table

大城市里の小女人 提交于 2019-12-08 01:54:53
问题 I need to build a class in this form namespace BestCompanyEver { public class PersonInfo { public string Name{get;set;} public int Age{get;set;} } } From a table Person that has columns Name and Age. Are there any ready to use solutions for this? I know I can implement this with T4 or Codesmith, but there should be somebody who already did it. 回答1: I found some nice T4 template I could use. Its from a project on codeplex. LINQ to SQL templates for T4 The template is hard to read an it took me

Is this a good/preferable pattern to Azure Queue construction for a T4 template?

筅森魡賤 提交于 2019-12-07 14:31:25
问题 I'm building a T4 template that will help people construct Azure queues in a consistent and simple manner. I'd like to make this self-documenting, and somewhat consistent. First I made the queue name at the top of the file, the queue names have to be in lowercase so I added ToLower() The public constructor uses the built-in StorageClient API's to access the connection strings. I've seen many different approaches to this, and would like to get something that works in almost all situations.

T4 template for an MVC Controller with Entity Framework - member properties of the host (MvcTextTemplateHost)?

橙三吉。 提交于 2019-12-07 07:59:06
问题 Does anyone have a full reference of the members of the Host object I can use in the T4 template ControllerWithContext.tt that comes with MVC 3? I've tried every google search I could think of, but the only relevant result is this page: http://blogs.msdn.com/b/webdevtools/archive/2009/01/29/t4-templates-a-quick-start-guide-for-asp-net-mvc-developers.aspx But it only shows 4 properties(ItemName, NameSpace, ExtraActionMethods, ControllerRootName) and not the full list. In the template there are

How to Exclude a T4 Template from a NuGet Package

守給你的承諾、 提交于 2019-12-07 07:30:35
问题 I'm creating a NuGet package the provides a client for my WebAPI project by reflecting over the ApiController s and creating classes for each one with methods that correspond to the actions defined on the controller. Unfortunately the .tt file is being included in the content folder when I run nuget.exe pack Client.csproj . I've tried creating a .nuspec file with a <files> directive, but I can't seem to exclude the file by itself. Does anyone know how to force the package to exclude the T4

T4 referenced assembly blocks build

半城伤御伤魂 提交于 2019-12-07 05:09:42
问题 In Visual Studio 2010 I have the following project layout: Solution project A class C class D project B T4 template The T4 template contains a assembly reference like this: <#@ assembly name="$(SolutionDir)\A\bin\Debug\A.dll" #> The template instantiates an instance of class C. When I run the T4 template the processor loads the project A's dll and correctly creates the output. The error arises when I want to change something in project A, say modify either class C or D. Unable to copy file

How to add new Scaffold used in Visual Studio 2013 Scaffolding?

こ雲淡風輕ζ 提交于 2019-12-07 02:40:55
问题 Is there a way to add a new Scaffold or override the Scaffolding functionality used in the new Visual Studio 2013 Scaffolding? The only documentation I can find on the internet is how to override the T4 templates using the CodeTemplates folder. I want to add a new Scaffold to the list when Add... > New Scaffold Item... It looks like in Visual Studio 2013 this has been rolled into a library (Microsoft.AspNet.Scaffolding.Mvc.5.0.dll) and registered in the GAC or as a VS Extension. http:/

T4 Preprocessed Template Debugging Not Working - Visual Studio 2010 RTM

折月煮酒 提交于 2019-12-06 23:07:10
问题 I am attempting to debug a preprocessed T4 template and I am not able to step into the class created by running the preprocessed template. I am able to create an instance of the class but as soon as I try to step into while debugging, a new window pops up that says No source available. There is no source code available for the current location. My understanding was that preprocessed templates could be debugged just like a normal c# class, is this not correct? Is there anything in particular

TextTransform.exe seems to only accept an older version of C#

两盒软妹~` 提交于 2019-12-06 14:44:45
When I expand T4 templates inside Visual Studio, I can use the full C# 3.0 syntax, including LINQ expressions, etc. When I expand it outside Visual Studio using TextTransform.exe it complains about LINQ expressions and other new features of C# 3.0. Is there a newer version of TextTransform.exe? The one I'm running is in: C:\Program Files\Common Files\Microsoft Shared\TextTemplating\1.2\TextTransform.exe 1.2 is the version of TextTransform that shipped with Visual Studio 2008. However, it will use C# compiler version 2.0 unless you specify version 3.5 in the template directive. 3.5 is the