Compile a C ++ application in C #

I use the following code to compile a single application in C ++:

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.

The assembly began 2012/01/04 03:32:16 Ψ¨.ΨΈ. MSBUILD: error MSB4014: the assembly was aborted due to an internal failure. MSBUILD: error MSB4014: System.InvalidCastException: cannot use an object of type 'System.Xml.XmlComment' to enter 'System.Xml.XmlElement'. MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren (XmlElement projectElement, String projectDirectoryLocation, Boolean importProject) MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessImportElementlelementlementlementlementlementmentml MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren (XmlElement projectElement, String projectDirectoryLocation, Boolean importProject) MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessImportElementlelelementlementlementlementlementmentml MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessProjectChildren (XmlElement projectElement, String projectDirectoryLocation, Boolean importProject) MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Project.ProcessMainProjectElement () B4014: when Microsoft.Build.BuildEngine.Project.RefreshProjectIfDirty () MSBUILD: error MSB4014: when Microsoft.Build.BuildEngine.Project.InternalLoadFromXmlDocument (XmlDocument projectXml, ProjectLoadSettings projectLoadSettings) MSBuild.bdild: MSBuild: Load (line projectFileName, BuildEventContext buildEventContext, ProjectLoadSettings projectLoadSettings) MSBUILD: error MSB4014:
at Microsoft.Build.BuildEngine.Engine.GetMatchingProject (existingProject project, String projectFullPath, BuildPropertyGroup globalPropertiesToUse, String toolsVersion, String [] targetNames, BuildEventContext buildEventContext, Boolean toolsVersionPeekedFromBjectBuild.BuildBuildFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBuildFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBjectFileBileFile BuildRequest buildRequest) MSBUILD: error MSB4014: with Microsoft.Build.BuildEngine.Engine.EngineBuildLoop (BuildRequest terminatingBuildRequest) MSBUILD: error MSB4014: at Microsoft.Build.BuildEngine.Engine.PostProjectEvalue [] ] targetNames, BuildPropertyGroup [] globalPropertiesPerProject, IDictionary [] targetOutputsPerProject, BuildSettings buildFlags, String [] toolVersions)

+6
source share
1 answer
  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 :)

+5
source

Source: https://habr.com/ru/post/905088/


All Articles