[英]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.