I use the following code to compile one C++ application:
Engine engine = new Engine();
engine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319";
BuildPropertyGroup group = new BuildPropertyGroup();
group.SetProperty("Configuration", "Debug");
engine.BuildEnabled = true;
FileLogger logger = new FileLogger();
logger.Parameters = @"logfile=C:\tmp\build.log";
engine.RegisterLogger(logger);
bool success = engine.BuildProjectFile(@"E:\sv_repos\Test\Test\VS2010\Test\Test\Test.vcxproj", new string[] { "Build" }, group);
engine.UnregisterAllLoggers();
if (success)
MessageBox.Show("build!");
But I get the following error, any idea will be appreciated.
Build started 2012/01/04 03:32:16 ب.ظ. MSBUILD : error MSB4014: The build was aborted because of an internal failure. MSBUILD : error MSB4014: System.InvalidCastException: Unable to cast object of type 'System.Xml.XmlComment' to type 'System.Xml.XmlElement'. MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement projectElement, String projectDirectoryLocation, Boolean importedProject) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessImportElement(XmlElement importElement, String projectDirectoryLocation, Boolean importedProject) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement projectElement, String projectDirectoryLocation, Boolean importedProject) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessImportElement(XmlElement importElement, String projectDirectoryLocation, Boolean importedProject) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement projectElement, String projectDirectoryLocation, Boolean importedProject) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessMainProjectElement() MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.RefreshProjectIfDirty() MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.InternalLoadFromXmlDocument(XmlDocument projectXml, ProjectLoadSettings projectLoadSettings) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Project.Load(String projectFileName, BuildEventContext buildEventContext, ProjectLoadSettings projectLoadSettings) MSBUILD : error MSB4014:
at Microsoft.Build.BuildEngine.Engine.GetMatchingProject(Project existingProject, String projectFullPath, BuildPropertyGroup globalPropertiesToUse, String toolsVersion, String[] targetNames, BuildEventContext buildEventContext, Boolean toolsVersionPeekedFromProjectFile) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Engine.BuildProjectFileInternal(BuildRequest buildRequest) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Engine.EngineBuildLoop(BuildRequest terminatingBuildRequest) MSBUILD : error MSB4014: at Microsoft.Build.BuildEngine.Engine.PostProjectEvaluationRequests(Project project, String[] projectFiles, String[][] targetNames, BuildPropertyGroup[] globalPropertiesPerProject, IDictionary[] targetOutputsPerProject, BuildSettings buildFlags, String[] toolVersions)
GCC, formerly for "GNU C Compiler", has grown over times to support many languages such as C ( gcc ), C++ ( g++ ), Objective-C, Objective-C++, Java ( gcj ), Fortran ( gfortran ), Ada ( gnat ), Go ( gccgo ), OpenMP, Cilk Plus, and OpenAcc. It is now referred to as "GNU Compiler Collection".
engine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319";
This is a versioning problem, your project is using an old version of the MSBuild engine. Visible from the stack trace, it is using the Microsoft.Build.BuildEngine.Project class. Which has this attribute:
[ObsoleteAttribute("This class has been deprecated. Please use Microsoft.Build.Evaluation.Project from the Microsoft.Build assembly instead.")]
MSBuild was significantly revised in .NET 4.0 as part of the major overhaul of the C++ build system. Which previously used a legacy build engine named VCBuild and a legacy project file format, it had the .vcproj filename extension. The MSBuild version you are using doesn't know anything about those changes and isn't capable of properly parsing a .vcxproj
You need to update the reference to the Microsoft.Build.Engine.dll reference assembly. The runtime version as displayed in the Properties window should show "v4.0.30319". I didn't have much luck using the Microsoft.Build.Evaluation.Project class, it is complaining about not being able to find .props files and looks in the wrong directory for them. It does however properly parse the .vcxproj file :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With