[wix-devs] MSBuildRunner

Ron Martin cpuwzd at comcast.net
Fri Feb 25 19:30:22 PST 2022


I stepped through MSBuildRunner from the WixE2EFixture to see what is 
happening on my computer with
both vS 2019 and VS 2022 installed. I've attached an annotated copy of 
the code so you can see what
I'm seeing.

Ron
-------------- next part --------------
        private static MsbuildRunnerResult InitAndExecute(string msbuildVersion, string projectPath, string[] arguments, bool x64)
        {
            lock (InitLock)
            {
                if (!Initialized)
                {
                    Initialized = true;
                    var vswhereResult = VswhereRunner.Execute(VswhereFindArguments, true);
                    if (vswhereResult.ExitCode != 0)
                    {
                        throw new InvalidOperationException($"Failed to execute vswhere.exe, exit code: {vswhereResult.ExitCode}. Output:\r\n{String.Join("\r\n", vswhereResult.StandardOutput)}");
                    }

                    string msbuild15Path = null;
                    string msbuild15Path64 = null;
                    string msbuildCurrentPath = null;
                    string msbuildCurrentPath64 = null;

                    foreach (var installPath in vswhereResult.StandardOutput)
                    // xxxxx vswhereResult.StandardOutput contains two results:
                    // xxxxx   1) The path to my VS 2019 Community installation
                    // xxxxx   2) The path to my VS 2022 Community installation
                    {
                        if (msbuildCurrentPath == null)
                        {
                            var path = Path.Combine(installPath, MsbuildCurrentRelativePath);
                            if (File.Exists(path))
                            {
                                msbuildCurrentPath = path; // xxxxx This is set to the path to my VS2019's
                                                           // xxxxx 32-bit MSBuild on the first pass
                            }
                        }

                        if (msbuildCurrentPath64 == null)
                        {
                            var path = Path.Combine(installPath, MsbuildCurrentRelativePath64);
                            if (File.Exists(path))
                            {
                                msbuildCurrentPath64 = path; // xxxxx This is set to the path to my VS2019's
                                                             // xxxxx 64-bit MSBuild on the first pass
                            }
                        }

                        if (msbuild15Path == null)
                        {
                            var path = Path.Combine(installPath, Msbuild15RelativePath);
                            if (File.Exists(path))
                            {
                                msbuild15Path = path; // xxxxx This remains set to null through both passes
                            }
                        }

                        if (msbuild15Path64 == null)
                        {
                            var path = Path.Combine(installPath, Msbuild15RelativePath64);
                            if (File.Exists(path))
                            {
                                msbuild15Path64 = path; // xxxxx This remains set to null through both passes
                            }
                        }
                    }

                    if (msbuildCurrentPath != null)
                    {
                        MsbuildCurrentRunner = new MsbuildRunner(msbuildCurrentPath); // xxxxx This uses the VS2019
                                                                                      // xxxxx 32-bit MSBuild
                    }

                    if (msbuildCurrentPath64 != null)
                    {
                        MsbuildCurrentRunner64 = new MsbuildRunner(msbuildCurrentPath64); // xxxxx This uses the VS2019
                                                                                          // xxxxx 64-bit MSBuild
                    }

                    if (msbuild15Path != null)
                    {
                        Msbuild15Runner = new MsbuildRunner(msbuild15Path); // xxxxx Never gets here because
                                                                            // xxxxx msbuild15Path is still null
                    }

                    if (msbuild15Path64 != null)
                    {
                        Msbuild15Runner64 = new MsbuildRunner(msbuild15Path64); // xxxxx Never gets here because
                                                                                // xxxxx msbuild15Path64 is still null
                    }
                }
            }

            MsbuildRunner runner;
            switch (msbuildVersion)
            {
                case "15":
                    {
                        runner = x64 ? Msbuild15Runner64 : Msbuild15Runner; // xxxxx runner would always be set to null here
                        break;
                    }
                case "Current":
                    {
                        runner = x64 ? MsbuildCurrentRunner64 : MsbuildCurrentRunner; // xxxxx runner would always be
                                                                                      // xxxxx for one of the two versions
                                                                                      // xxxxx of VS 2019 MSBuild here
                        break;
                    }
                default:
                    {
                        runner = x64 ? MsbuildCurrentRunner64 ?? Msbuild15Runner64 // xxxxx Can't win here, either
                                     : MsbuildCurrentRunner ?? Msbuild15Runner;
                        break;
                    }
            }

            if (runner == null)
            {
                throw new InvalidOperationException($"Failed to find an installed{(x64 ? " 64-bit" : String.Empty)} MSBuild{msbuildVersion}");
            }

            return runner.ExecuteCore(projectPath, arguments); // xxxxx Tries to use tools version v123 with VS 2019 MSBuild!
        }


More information about the wix-devs mailing list