我有一个文本模板片段,它生成一个Solution
具有Assemblies
属性的类,以列出 Visual Studio 解决方案中的所有项目程序集,以帮助配置 IoC 容器(GitHub、NuGet)。但是,当项目放在解决方案文件夹中时,它会失败。如何使该脚本的解决方案文件夹透明?有问题的代码是:
<#+
class SolutionAssemblyNames : IEnumerable<string>
{
public SolutionAssemblyNames(ITextTemplatingEngineHost host)
{
Host = host;
}
public IEnumerator<string> GetEnumerator() => Assemblies.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
IEnumerable<string> Assemblies => Projects
.Select(p => p?.Properties?.Item("AssemblyName")?.Value as string)
.Distinct().Where(a => !string.IsNullOrWhiteSpace(a));
IEnumerable<Project> Projects => VisualStudio.Solution.Projects.OfType<Project>();
DTE VisualStudio => (Host as IServiceProvider).GetService(typeof(DTE)) as DTE;
ITextTemplatingEngineHost Host { get; }
}
#>