如何根据解决方案文件类的配置列出项目



您如何列出从解决方案类别的特定配置的所有项目?

我能够得到所需的结果:

(下面的代码段从ViewModel取出(

using Microsoft.Build.Construction;
using System.Collections.ObjectModel;
// Step #1 - Instantiate SolutionFile from a solution file name
    vm.SolutionFile = SolutionFile.Parse("SampleSolution.sln");
// Step #2 - Get List of Solution Configurations
    var list = new ObservableCollection<string>();
    foreach (var solutionConfiguration in vm.SolutionFile.SolutionConfigurations)
    {
        list.Add(solutionConfiguration.ConfigurationName + "|" + solutionConfiguration.PlatformName);
    }
    vm.SolutionConfigurations = list;
// Step #3 - Select the desired Configuration 
    vm.Configuration = [select a configuration from vm.SolutionConfigurations]
// Step #4 Get List of Projects based on Configuration
    var list = new ObservableCollection<string>();
    foreach (var project in vm.SolutionFile.ProjectsByGuid)
    {
        foreach (var projectConfiguration in project.Value.ProjectConfigurations)
        {
            if (vm.Configuration.Contains(projectConfiguration.Key.ToString()))
            {
                if (projectConfiguration.Value.IncludeInBuild)
                {
                    list.Add(project.Value.ProjectName);
                    break;
                }
            }
        }
    }
    vm.ProjectsInConfiguration = list;

相关内容

  • 没有找到相关文章

最新更新