我在Visual Studio中建立與TextTemplatingFileGenerator自定義工具類T4模板:如何在T4模板中輸出名稱空間?
<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#
var className = System.IO.Path.GetFileNameWithoutExtension(Host.TemplateFile);
var namespaceName = "MyNamespace";
#>
namespace <#= namespaceName #>
{
public static class <#= className #>
{
// some generated code
}
}
我怎樣才能在Visual Studio中的「自定義工具命名空間」屬性的值,所以不必須對命名空間進行硬編碼?
我甚至會對C#項目的默認命名空間感到滿意。
不幸的是,這個技巧在使用基於MSBuild的時候不起作用轉化系統(如圖所示:http://www.olegsych.com/2010/04/understanding-t4-msbuild-integration/)。遊民。 :( – 2013-08-17 04:24:02
該功能使調試失敗 – 2017-05-01 20:10:09