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.