gpt4 book ai didi

.net - 在 C# 上编译 C++ 应用程序

转载 作者:行者123 更新时间:2023-12-03 19:01:02 24 4
gpt4 key购买 nike

我使用以下代码编译一个 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!");

但我收到以下错误,任何想法将不胜感激。

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)

最佳答案

   engine.BinPath = @"C:\WINDOWS\Microsoft.NET\Framework\v4.0.30319";

这是一个版本控制问题,您的项目使用的是旧版本的 MSBuild 引擎。从堆栈跟踪中可以看出,它正在使用 Microsoft.Build.BuildEngine.Project class .其中有这个属性:
[ObsoleteAttribute("This class has been deprecated. Please use Microsoft.Build.Evaluation.Project from the Microsoft.Build assembly instead.")]

作为 C++ 构建系统大修的一部分,MSBuild 在 .NET 4.0 中进行了重大修订。以前使用名为 VCBuild 的旧构建引擎和旧项目文件格式,它具有 .vcproj 文件扩展名。您使用的 MSBuild 版本对这些更改一无所知,并且无法正确解析 .vcxproj

您需要更新对 Microsoft.Build.Engine.dll 引用程序集的引用。 “属性”窗口中显示的运行时版本应显示“v4.0.30319”。我在使用 Microsoft.Build.Evaluation.Project 类时运气不佳,它提示无法找到 .props 文件并在错误的目录中查找它们。但是它确实正确解析了 .vcxproj 文件:)

关于.net - 在 C# 上编译 C++ 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8726590/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com