编译 c++在c#上的应用
我使用以下代码来编译一个 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!");
但我收到以下错误,任何想法将不胜感激。
构建于 2012/01/04 03:32:16 开始。 MSBUILD:错误MSB4014: 由于内部故障,构建被中止。 MSBUILD:错误 MSB4014:System.InvalidCastException:无法转换类型的对象 “System.Xml.XmlComment”以键入“System.Xml.XmlElement”。微软构建: 错误 MSB4014:位于 Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement 项目元素、字符串、项目目录位置、布尔值 importProject) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Project.ProcessImportElement(XmlElement importElement、字符串、项目目录位置、布尔值 importProject) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement 项目元素、字符串、项目目录位置、布尔值 importProject) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Project.ProcessImportElement(XmlElement importElement、字符串、项目目录位置、布尔值 importProject) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Project.ProcessProjectChildren(XmlElement 项目元素、字符串、项目目录位置、布尔值 importProject) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Project.ProcessMainProjectElement() MSBUILD:错误MSB4014:位于 Microsoft.Build.BuildEngine.Project.RefreshProjectIfDirty() MSBUILD : 错误 MSB4014:位于 Microsoft.Build.BuildEngine.Project.InternalLoadFromXmlDocument(XmlDocument projectXml、ProjectLoadSettings projectLoadSettings) MSBUILD:错误 MSB4014:在 Microsoft.Build.BuildEngine.Project.Load(字符串 项目文件名,BuildEventContext buildEventContext, ProjectLoadSettings projectLoadSettings) MSBUILD:错误 MSB4014:
在 Microsoft.Build.BuildEngine.Engine.GetMatchingProject(项目 现有项目、字符串项目完整路径、BuildPropertyGroup globalPropertiesToUse,字符串工具版本,字符串[]目标名称, BuildEventContext buildEventContext,布尔值 toolsVersionPeekedFromProjectFile) MSBUILD:错误 MSB4014:位于 Microsoft.Build.BuildEngine.Engine.BuildProjectFileInternal(BuildRequest buildRequest) MSBUILD : 错误 MSB4014: 在 Microsoft.Build.BuildEngine.Engine.EngineBuildLoop(BuildRequest 终止BuildRequest)MSBUILD:错误MSB4014:位于 Microsoft.Build.BuildEngine.Engine.PostProjectEvaluationRequests(项目 项目,字符串 [] 项目文件,字符串 [] [] 目标名称, BuildPropertyGroup[] globalPropertiesPerProject、IDictionary[] targetOutputsPerProject、BuildSettings buildFlags、字符串 [] 工具版本)
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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是版本控制问题,您的项目正在使用旧版本的 MSBuild 引擎。从堆栈跟踪中可以看出,它使用的是 Microsoft.Build.BuildEngine.Project 类。其中具有以下属性:
作为 C++ 构建系统重大改革的一部分,MSBuild 在 .NET 4.0 中进行了重大修改。以前使用名为 VCBuild 的旧版构建引擎和旧版项目文件格式,它的文件扩展名为 .vcproj。您使用的 MSBuild 版本对这些更改一无所知,并且无法正确解析 .vcxproj
您需要更新对 Microsoft.Build.Engine.dll 参考程序集的引用。 “属性”窗口中显示的运行时版本应显示“v4.0.30319”。我在使用 Microsoft.Build.Evaluation.Project 类时运气不佳,它抱怨无法找到 .props 文件并在错误的目录中查找它们。但是它确实正确解析了 .vcxproj 文件:)
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:
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 :)