我需要通过代码编译一个用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
。
任何指向正确方向的人都会非常感激。
答案 0 :(得分:0)
PROTIP:下次,孩子们,正确阅读错误消息。我作为平台“任何CPU”而不是“AnyCPU”传递(注意正确术语中的非存在空间)。