Building a C ++ solution using MSBuild in a C # application

I'm currently trying to use Microsoft.Build.Execution.BuildManager to create a C ++ solution from a winforms C # application.

From other posts, I came up with the following code that uses Logger so that I can see some output. BuildSubmission.BuildResult.OverallResult always fails when trying to create a C ++ application.

 string projectFileName = "mySolution.sln"; ProjectCollection pc = new ProjectCollection(); Dictionary<string, string> GlobalProperty = new Dictionary<string, string>(); GlobalProperty.Add("Configuration", "Release"); GlobalProperty.Add("Platform", "Win32"); BuildParameters bp = new BuildParameters(pc); bp.Loggers = new[] { new ConsoleLogger { Verbosity = LoggerVerbosity.Minimal, ShowSummary = true, SkipProjectStartedText = true } }; BuildManager.DefaultBuildManager.BeginBuild(bp); BuildRequestData BuildRequest = new BuildRequestData(projectFileName, GlobalProperty, null, new string[] { "Clean" }, null); BuildSubmission BuildSubmission = BuildManager.DefaultBuildManager.PendBuildRequest(BuildRequest); BuildSubmission.Execute(); BuildManager.DefaultBuildManager.EndBuild(); if (BuildSubmission.BuildResult.OverallResult == BuildResultCode.Failure) { throw new Exception(); } 

When I run this code, I get the following output:

C: \ Program Files (x86) \ MSBuild \ Microsoft.Cpp \ v4.0 \ V140 \ Microsoft.CppClean.targets (76.5): error MSB4127: task "CppClean" cannot be created from assembly "C: \ Program Files (x86) \ MSBuild \ Microsoft.Cpp \ v4.0 \ V140 \ Microsoft.Build.CppTasks.Common.dll ". Ensure that the task assembly is built using the same version of the Microsoft.Build.Framework assembly as on your computer, and that your host application does not skip binding redirection for Microsoft.Build.Framework. Cannot pass an object of type "Microsoft.Build.CPPTasks.CPPClean" to enter "Microsoft.Build.Framework.ITask".

C: \ Program Files (x86) \ MSBuild \ Microsoft.Cpp \ v4.0 \ V140 \ Microsoft.CppClean.targets (76.5): error MSB4060: task "CppClean" was declared or used incorrectly, or failed during construction. Check the spelling of the task name and assembly name.

Can someone explain why I am getting this message, how can I solve it?

PS. I would prefer solutions that work with updating an object / variable in C # code or update a parameter in a C ++ solution for those that require manual updating of MSBuild or Visual Studio files. I work in an environment with several developers, and I would prefer not to distribute these changes to everyone in the team so that this application works for them.

+7
source share

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


All Articles