Programmatically triggering MSBuild is giving build error for Edit & Continue /ZI property

Peeyush Chaurasia 0 Reputation points
2024-01-23T06:54:45.3166667+00:00

I'm simulating custom debugger with Edit and Continue through VSExtension, so during live debug session, I'm halted at breakpoint, using dte, MSBuild etc. programmatically I will compile custom file generate FileName.obj and manually patch exe.

        logger.Verbosity = LoggerVerbosity.Detailed;
        MsBuild.Execution.BuildRequestData buildRequest = new MsBuild.Execution.BuildRequestData(projectPath, properties, null, new string[] { "ClCompile" /*target*/ }, null);
        MsBuild.Execution.BuildParameters buildParams = new MsBuild.Execution.BuildParameters()
        {
            DetailedSummary = true, /*false,*/
            Loggers = new List<ILogger>() { logger }
        };

        ThreadPool.QueueUserWorkItem((Object) =>
        {
        try
        {
            MsBuild.Execution.BuildResult result = MsBuild.Execution.BuildManager.DefaultBuildManager.Build(buildParams, buildRequest);
            if (result.OverallResult == MsBuild.Execution.BuildResultCode.Success)
            {
                logger.Write(String.Format("compile succeeded \"{0}\"\n", selectedFiles)); //Test.cpp
            }
        }
        }

MSBuild succeeds for Project default debug property /Zi, but when I change it to /ZI EDIT and Continue I get build failure error project.IDB file already in use, with suggestion to use /FS.

Test.cpp(0): error C1041: cannot open program database 'C:\Project\Debug\vc142.idb'; if multiple CL.EXE write to the same .PDB file, please use /FS

even if I set /FS in project properties page it is not resolving programmatic build issue. enter image description here enter image description here If I can change debug output path to some other path/set of files in Programmatically invoked MSBuild it will likely resolve, but unable to identify how to set it through MS BuildRequestData and BuildParameters.

I'm passing follwoing properties dictionary to MSBuild Parmeteres:

       properties.Add("SelectedFiles", DocName);
        properties.Add("BuildProjectReferences", "false");
        properties.Add("SolutionDir", val("$(SolutionDir)"));
        properties.Add("SolutionExt", val("$(SolutionExt)"));
        properties.Add("SolutionName", val("$(SolutionName)"));
        properties.Add("SolutionFileName", val("$(SolutionFileName)"));
        properties.Add("SolutionPath", val("$(SolutionPath)"));

Added Note 1: Going through MSDN found there is VCconfig class using which I can change outputpath and intermediateDirectory, but not sure how to make this work, as MSBuild is one class and VCConfiguration is unrelated different class.

But

  1. if use /ZI MSBuild fails with vc142.idb in use error. So may be changing paths for programmatic MSBuild will solve Error 1.
  2. VS detects EXE is not in synch with Custom File so give Stop Debugging error box. CodeDebuggung-EditNContinue-error And for Error2 somehow VS detection has to be suppressed to continue debugging. How?
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,612 questions
Visual Studio Extensions
Visual Studio Extensions
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Extensions: A program or program module that adds functionality to or extends the effectiveness of a program.
189 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
962 questions
{count} votes