'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 1:[1]
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...
);
});
Solution 2:[2]
To add to this answer: https://stackoverflow.com/a/70097525/569302
I am using Visual Studio Community 2022 right now:
For me the path was: C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Current\Bin\MSBuild.exe
Solution 3:[3]
A better way to solve this issue is using environment variable MSBUILD_EXE
which should point to MSBuild.exe. Then instead of hardcoding path in sources use property MSBuildTasks.MSBuildPath
:
MSBuildTasks.MSBuild(settings => settings
.SetProcessToolPath(MSBuildTasks.MSBuildPath)
.EnableRestore()
.SetSolutionFile(solution)
.SetConfiguration(Configuration));
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Husam Ebish |
Solution 2 | Jesus is Lord |
Solution 3 | Pavel Zemlianikin |