engine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319";
This is a version issue, your project uses the old version of the MSBuild engine. Visible from the stack trace, it uses the Microsoft.Build.BuildEngine.Project class . This attribute has:
[ObsoleteAttribute("This class has been deprecated. Please use Microsoft.Build.Evaluation.Project from the Microsoft.Build assembly instead.")]
MSBuild has been significantly redesigned in .NET 4.0 as part of a major overhaul of the C ++ build system. The previously used mechanism for creating obsolete versions named VCBuild and the obsolete project file format, it had a .vcproj file extension. The version of MSBuild you are using knows nothing about these changes and cannot parse the .vcxproj file correctly
You need to update the reference to the Microsoft.Build.Engine.dll reference assembly. The execution version displayed in the Properties window should show "v4.0.30319". I was not very lucky using the Microsoft.Build.Evaluation.Project class, it complains that it could not find the .props files and is looking for the wrong directory in them. However, it parses the .vcxproj file correctly :)
source share