有趣的是, 在我用不同的字眼张贴了这个问题后, 我谷歌上用不同的字眼搜索, 找到了一些东西: T4 模板, 处理内置时有不错的错误... 这里的文章是:
"http://www.wynia.org/wewpress/2010/04/t4-template-for-applates-appings-access-in-config-files" rel=“nofollow”>T4 AppsSettings Access in Config 文件
我不得不更改文章中提供的T, 以便在我当前的环境中运作(VS 11 Beta + ASP.NET MVC 4 App)。
How to use?
下载 < a href=\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
这些是Im使用的进口品:
<#@ template language="C#" debug="true" hostspecific="true" #>
<#@ output extension=".cs" #>
<#@ Assembly Name="System.Core.dll" #>
<#@ assembly name="EnvDTE" #>
<#@ Assembly name="System.Configuration"#>
<#@ import namespace="System" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Diagnostics" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Specialized"#>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Configuration" #>
Web.config
中的一些应用程序设置在它们的名称中有一个冒号( : ), 例如 < code> webpages: Version 。 这就是我使它发挥作用的手法 :
public static string <#=setting.Replace(":", "")#>
{
get
{
return getConfigSetting("<#=setting#>");
}
}
注意 < code> section. replace 上面的 < code> replace 。
如果您愿意的话, 您也可以调试 T4 模板。 请遵循这里描述的步骤 :
< a href=" http://www.hanselman.com/blog/ Tiny HappyFeatures1T4TemplateDebugging InVisualStudio2012.aspx?utm_source=feedburner&utm_medied=feed&utm_campaign=Feed%3a%20ScottHanselman%20%2028Scott%20Hanselman%20-%20ComputerZen.com%29&utm_content=Google%20Reader” rel=“nofolve” 提示#1 -2012视觉工作室T4模板调试