我正在使用Microsoft.CodeAnalysis和.MSBuild来加载解决方案,它的项目和检索项目OutputFilePath。麻烦是Debug和Release有不同的,我无法想出一种在解决方案配置之间切换的方法。知道如何设置将使用哪种配置?
MSBuildWorkspace workspace = MSBuildWorkspace.Create();
workspace.LoadMetadataForReferencedProjects = true;
Solution solution = workspace.OpenSolutionAsync("someSolution.sln").Result;
foreach (Project project in solution.Projects)
Console.Out.WriteLine(project.OutputFilePath);
workspace.CloseSolution();
答案 0 :(得分:1)
某些MSBuild属性(通常是输出路径)取决于构建项目的配置。您必须在创建工作区时指定该配置。
例如:
var properties = new Dictionary<string, string>
{
{ "Configuration", "Debug" } // Or "Release", or whatever is known to your projects.
// ... more properties that could influence your property,
// e.g. "Platform" ("x86", "AnyCPU", etc.)
};
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);
workspace.CloseSolution();