简体   繁体   English

弄清楚为什么 Microsoft.Build.Evaluation.Project.Build() 返回 false

[英]Figure out why Microsoft.Build.Evaluation.Project.Build() returns false

I'm trying to build C# projects using .csproj files.我正在尝试使用 .csproj 文件构建 C# 项目。 For this I'm using the following code:为此,我使用以下代码:

Microsoft.Build.Evaluation.Project project = new Microsoft.Build.EvaluationProject(projectFile);
bool success = project.Build();

But not all projects are build and for some I get false as the result of project.Build() .但并非所有项目都是构建的,对于某些项目,由于project.Build()的结果,我得到了false Any ideas how to understand what is going wrong?任何想法如何理解出了什么问题?

Or maybe anyone can suggest an alternative way to compile projects using .csproj files?或者也许任何人都可以建议使用 .csproj 文件编译项目的替代方法?

You need to add an ILogger to the Build method as a parameter.您需要将ILogger作为参数添加到Build方法中。 I suggest implementing one as the MSDN article suggests .我建议按照 MSDN 文章的建议实施一个。 Just copy paste their code, add any missing references and you'll be fine.只需复制粘贴他们的代码,添加任何缺失的引用,你就可以了。

Then you can call Build as follows:然后你可以调用Build如下:

Microsoft.Build.Evaluation.Project project = new Microsoft.Build.Evaluation.Project(projectFile);
BasicFileLogger logger = new BasicFileLogger();
logger.Parameters = logFilePath;
logger.Verbosity = LoggerVerbosity.Normal; //Increase it if you don't get enough data
bool success = project.Build(logger);

The example logger will write all data that you would see during a normal build to the file at logFilePath .示例记录器会将您在正常构建期间看到的所有数据写入logFilePath文件。 Based on that you should be able to discern the issue.基于此,您应该能够识别问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用Microsoft.Build.Evaluation发布数据库项目(.sqlproj) - Using Microsoft.Build.Evaluation to publish a database project (.sqlproj) 如何使用 Microsoft.Build.Evaluation.Project.RemoveItem - How to use Microsoft.Build.Evaluation.Project.RemoveItem 使用Microsoft.Build.Evaluation.Project.RemoveItem删除的项目 - Removed item using Microsoft.Build.Evaluation.Project.RemoveItem 从C#运行Microsoft.Build.Evaluation.Project的并行构建 - Run parallel build of Microsoft.Build.Evaluation.Project from C# 无法弄清楚为什么集合会为布尔属性返回false? - Can't figure out why collection returns false for bool property? Microsoft.Build.Evaluation.Project 在VS中添加文件夹和文件强制刷新项目 - Microsoft.Build.Evaluation.Project add folder and file force refresh of project in VS 如何在MSBuild 14.0中重新加载Microsoft.Build.Evaluation.Project - How can I reload a Microsoft.Build.Evaluation.Project in MSBuild 14.0 为什么Microsoft.Build.Evaluation在64位PC上将$(ProgramFiles)评估为“ c:\\ program files”? - Why does Microsoft.Build.Evaluation evaluate $(ProgramFiles) as “c:\program files” on 64 bit PC? 使用 Microsoft.Build API 构建项目 - Build project with Microsoft.Build API 无法在 VS2017 中使用 Microsoft.Build.Evaluation - Can't use Microsoft.Build.Evaluation in VS2017
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM