Accessing Projects via DTE in C# T4 Template

前端 未结 2 929
既然无缘
既然无缘 2020-12-09 20:42

I\'m currently trying to iterate over all of my projects (sharepoint) to get all feature guids into an file. there i want to prefix them with the projects name. My problem i

相关标签:
2条回答
  • 2020-12-09 21:26

    Try the Solution.Projects property:

    <#@ template language="C#" debug="true" hostspecific="true" #>
    <#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
    <#@ assembly name="EnvDTE" #>
    <#@ assembly name="EnvDTE80" #>
    <#@ assembly name="VSLangProj" #>
    <#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
    <#@ import namespace="EnvDTE" #>
    <#@ import namespace="EnvDTE80" #>
    <#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
    <#@ output extension=".txt" #>
    <#
    
    var hostServiceProvider = (IServiceProvider)this.Host;
    var dte = (DTE)hostServiceProvider.GetService(typeof(DTE));
    
    foreach (Project project in dte.Solution)
    {
        #>
        <#= project.Name #>
        <#
    }
    
    #>
    
    0 讨论(0)
  • 2020-12-09 21:29

    Try this

            var item = dte.Solution.Projects.GetEnumerator();
            while (item.MoveNext())
            {
                var project = item.Current as EnvDTE.Project;
                if (project == null)
                {
                    continue;
                }
                ...
            }
    
    0 讨论(0)
提交回复
热议问题