1
votes

I'm trying to use the Microsoft.Build libraries to compile a project from my application. All of the projects I will possibly use this to build are .Net 4.7.1 projects in VS2017. Here is the code I have in question and the error I am receiving:

var loggerPath = $"C:\\temp\\{FilenameOnly}BuildLog.txt";

var collection = ProjectCollection.GlobalProjectCollection;

var logger = new FileLogger();
logger.Parameters =  $"logfile={loggerPath}";

collection.RegisterLogger(logger);

var project = collection.LoadProject(FileWithPath);
project.SetProperty("Configuration", buildConfiguration);
project.Build();

Microsoft.Build.Exceptions.InvalidProjectFileException: 'The default XML namespace of the project must be the MSBuild XML namespace. If the project is authored in the MSBuild 2003 format, please add xmlns="http://schemas.microsoft.com/developer/msbuild/2003" to the element. If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format.

It sounds like I'm using the wrong MSBuild and I figured I was referencing the wrong Microsoft.Build.x.dlls so I tried switching to the ones in C:\Program Files (x86)\MSBuild\14.0\Bin for the same exception.

1
Very likely you need MSBuild 15.Lex Li
Thanks, I ended up getting MSBuild 15 (per your suggestion) via nuget package and stumbled through a few more complications to get it working.Franklin S.

1 Answers

0
votes

I ended up needing to get MSBuild 15 via nuget package. I also encountered a few more issues that would have left me seeking alternatives if I had not stumbled across this link:

MSBuild 15: The "Error" task could not be instantiated