Search code examples
c#msbuildvisual-studio-2022nuke-build

NUKE Build: Could not find a suitable MSBuild instance (Visual Studio 2022)


After upgrade Visual Studio 2019 to 2022, I got the following error when I try to build the project with NUKE Build (Debug/Release):

╬════════════
║ Compile
╬═══

Assertion failed: Could not find a suitable MSBuild instance.
   at Nuke.Common.Tools.MSBuild.MSBuildToolPathResolver.Resolve(Nullable`1 msBuildVersion, Nullable`1 msBuildPlatform)
   at Nuke.Common.Tools.MSBuild.MSBuildSettings.GetProcessToolPath()
   at Nuke.Common.Tools.MSBuild.MSBuildSettings.get_ProcessToolPath()
   at Nuke.Common.Tooling.ProcessTasks.StartProcess(ToolSettings toolSettings)
   at Nuke.Common.Tools.MSBuild.MSBuildTasks.MSBuild(MSBuildSettings toolSettings)
   at Nuke.Common.Tools.MSBuild.MSBuildTasks.MSBuild(Configure`1 configurator)
   at AREGIS.Build.DeagBuild.<get_Compile>b__21_1() in C:\Work.Vertex\Vertex\40 Build\DeagBuild.cs:line 98
   at Nuke.Common.Execution.BuildExecutor.<>c.<Execute>b__4_2(Action x)
   at Nuke.Common.Utilities.Collections.EnumerableExtensions.ForEach[T](IEnumerable`1 enumerable, Action`1 action)
   at Nuke.Common.Execution.BuildExecutor.Execute(NukeBuild build, ExecutableTarget target, IReadOnlyCollection`1 previouslyExecutedTargets, Boolean failureMode)


Repeating warnings and errors:
Assertion failed: Could not find a suitable MSBuild instance.

Compile method:

        Target Compile => _ => _
        .DependsOn(this.RestoreFramework)
        .Executes(() =>
        {
            var compileOutput = MSBuild(x => x
                .SetTargetPath(this.MySolution)
                .Set...
                .Set...
                );
        });

Target framework: .NET Framework 4.8

Is there any way to fix it?


Solution

  • I have to set process tool path. I fixed it by adding the path of MSBuild.exe

    .SetProcessToolPath(@"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe")
    

    The compile method should be:

     Target Compile => _ => _
        .DependsOn(this.RestoreFramework)
        .Executes(() =>
        {
            var compileOutput = MSBuild(x => x
                .SetProcessToolPath(@"C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Current\Bin\MSBuild.exe")
                .SetTargetPath(this.MySolution)
                .Set...
                .Set...
                );
        });