0

I am trying to figure out which project is enabled/disabled in respective build configuration/platform setup. Where could I find this "project.BuildsInCurrentConfiguration" information please?

var properties = new Dictionary<string, string>
{
   { "Configuration", "Debug" },
   { "Platform", "x86"}
};

MSBuildWorkspace workspace = MSBuildWorkspace.Create(properties);
workspace.LoadMetadataForReferencedProjects = true;
Solution solution = workspace.OpenSolutionAsync("someSolution.sln").Result;
foreach (Project project in solution.Projects)
            Console.Out.WriteLine($"{project.OutputFilePath} is enabled in this build setup: {project.BuildsInCurrentConfiguration}");
workspace.CloseSolution();

I would have thought I wouldn't be offered the projects that are not part of the picked configuration/platform, but solution.Projects shows me all of them regardless build setup.

Jan Hyka
  • 47
  • 5

1 Answers1

0

I don't think Roslyn really has most of that information right now (I'm not sure if it ever would; but I would hope it would). I don't see anything related to a "configuration" for a project with the Roslyn APIs for example. That seems to be delegated to the DTE interfaces. You can get at platform type in a Roslyn project, so conceptually you could only get projects that would apply to a given type of build:

var rolsynProjects = solution.Projects
    .Where(p => p.CompilationOptions.Platform == Platform.X86);

but, things like "DEBUG" configuration seem to only be available via DTE--which isn't that hard to get at. e.g.

 var project = DTE.Solution.Projects
    .Where(p=>p.FullName == rolsynProjects.First().FilePath).FirstOrDefault();

And from that VS project, you can get at its ConfigurationManager

Peter Ritchie
  • 35,463
  • 9
  • 80
  • 98