以编程方式从T4访问PropertyGroup中定义的C#项目自定义属性
我在C#project的.csproj文件中定义了自定义属性:以编程方式从T4访问PropertyGroup中定义的C#项目自定义属性,c#,visual-studio,visual-studio-2015,t4,C#,Visual Studio,Visual Studio 2015,T4,我在C#project的.csproj文件中定义了自定义属性: ... <PropertyGroup> <SomeMineProperty>Hi there!</SomeMineProperty> </PropertyGroup> ... 有几十个属性,但SomeMineProperty不在其中 <#@ template debug="false" hostspecific="true" language="C#" #> &l
...
<PropertyGroup>
<SomeMineProperty>Hi there!</SomeMineProperty>
</PropertyGroup>
...
有几十个属性,但SomeMineProperty
不在其中
<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="EnvDTE" #>
<#@ import namespace="EnvDTE" #>
<#@ output extension=".txt" #>
<#
var project= this.FindProject();
var props = project.ConfigurationManager.ActiveConfiguration.Properties; // Same result for project.Properties
#>
count:<#=props.Count#>
<#foreach (Property prop in props){#>
<#= prop.Name #> = <#= prop.Value #>
<#}#>
<#+
Project FindProject()
{
var serviceProvider = (IServiceProvider)this.Host;
var dte = (DTE)serviceProvider.GetService(typeof(DTE));
var item = dte.Solution.FindProjectItem(this.Host.TemplateFile);
if (item != null && item.ContainingProject != null)
return item.ContainingProject;
throw new InvalidOperationException(string.Format("Cannot find project for {0} template", this.Host.TemplateFile));
}
#>