指定解决方案配置&;Debug| anycpu &;是无效的"通过Microsoft.Build构建解决方案时

本文关键字:解决方案 通过 quot Microsoft 构建 Build anycpu 配置 Debug 无效 | 更新日期: 2023-09-27 18:15:15

我需要通过代码编译一个用VB编写的旧WPF项目。为此,我正在用c#编写一个类库,用于加载解决方案并调用构建过程。

代码如下:

// solution_file is a FileInfo object that points to the .sln file
// logger is a class that implements ILogger
var solution = new ProjectCollection();
var solution_properties = new Dictionary<string, string>();
solution_properties.Add("Configuration", "Debug");
solution_properties.Add("Platform", "AnyCPU");
var build_parameters = new BuildParameters(solution);
var logger = new SimpleLogger();
build_parameters.Loggers = new List<ILogger>() { logger };
var build_request = new BuildRequestData(
    solution_file.FullName,
    solution_properties,
    "14.0",
    new string[] { "Build" },
    null);
var build_result = BuildManager.DefaultBuildManager.Build(build_parameters, build_request);
if (build_result.OverallResult != BuildResultCode.Success)
    throw new Exception();

问题是,在任何情况下,构建失败,并出现以下错误:

The specified solution configuration "Debug|AnyCPU" is not valid. Specify a valid solution configuration with the properties Configuration and Platform (eg. MSBuild.exe Solution.sln /p:Configuration=Debug /p:Platform="Any CPU") or leave these properties empty to use the default solution configuration.

(消息可能不是准确的翻译,我是从西班牙语翻译过来的)

配置(调试或发布)和平台(x86, x64或AnyCPU)的任何组合都以相同的错误失败(唯一改变的是The specified solution configuration Debug|AnyCPU is not valid部分)。如果我将这些属性保留为空,则错误信息与Debug|MCD相同,而不是Debug|AnyCPU

请指教。

指定解决方案配置&;Debug| anycpu &;是无效的"通过Microsoft.Build构建解决方案时

PROTIP:孩子们,下次请正确阅读错误消息。我通过平台"任何CPU"而不是"AnyCPU"(注意在正确的术语中不存在空间)。

相关文章: