MSBuild: Could not locate executable #3476
-
Prerequisites
Cake runnerCake runner for .NET Framework Cake version1.2.0 Operating systemWindows Operating system architecture64-Bit CI ServerNo response What are you seeing?I'm trying Cake for build .NET Framework projects. I wrote a simple script for the test: var target = Argument("target", "Test");
Task("Test")
.Does(() => {
NuGetRestore("./test/Test.sln");
MSBuild("./test/Test.sln", new MSBuildSettings {
Verbosity = Verbosity.Minimal,
ToolVersion = MSBuildToolVersion.VS2019,
Configuration = "Release",
});
});
RunTarget(target); And get output:
Sometimes he found and forcibly used .NET 4.0 from Windows 10, with error at LangVersion. In Visual Studio and Rider, Test.sln building successfully What is expected?Build Steps to Reproduce
Output log
|
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 3 replies
-
@zgdump if you put the restore in one task and build in another, is it the NuGetRetore och MSBuild alias that fails? If Visual Studio isn't installed in any of the standard locations, then I would recommend using one of the VSWhereAliases, there's a blog post on using it here . If it's a modern CSProj file, looking at the .NET CLI aliases might be another option instead of using NuGet.exe and MSBuild. |
Beta Was this translation helpful? Give feedback.
-
@devlead I divide into different tasks, delete work with nuget. The error is same. I'm tried to use VSWhere: #tool nuget:?package=vswhere
DirectoryPath vsLatest = VSWhereLatest(new VSWhereLatestSettings { Requires = "Microsoft.VisualStudio.Workload.ManagedDesktop"});
FilePath msBuildPathX64 = (vsLatest==null)
? null
: vsLatest.CombineWithFilePath("./MSBuild/Current/Bin/MSBuild.exe");
var target = Argument("target", "Test");
Task("Test")
.Does(() =>
{
//NuGetRestore("./test/Test.sln");
MSBuild("./test/Test.sln", new MSBuildSettings {
ToolPath = msBuildPathX64,
});
});
RunTarget(target); It almost worked, though he is now trying to use the ancient and built-in.NET 4.0 from Windows:
As a consequence, the error:
My project needs .NET Framework 4.6 |
Beta Was this translation helpful? Give feedback.
This comment has been hidden.
This comment has been hidden.
-
@zgdump Cake expects MSBuild to be in one of the default locations based on the version you specify and the different editions that exist. In your case you're specifying
It seems you have Visual Studio installed in a non-default location on If you want to continue to use the custom install path you have, then @devlead's suggestion above of using VSWhere would be ideal. You're going to have to play with VSWhere and try the different aliases to see if you can (dynamically) find the path to your custom MSBuild install. You can try locating the latest version that has MSBuild installed, for example: #tool "nuget:?package=vswhere&version=2.8.4"
var latestMSBuildPath = VSWhereLatest(new VSWhereLatestSettings { Requires = "Microsoft.Component.MSBuild"});
Information("latestMSBuildPath: {0}", latestMSBuildPath); You can list all versions that VSWhere can detect, with #tool "nuget:?package=vswhere&version=2.8.4"
var allInstalled = VSWhereAll();
foreach (var installPath in allInstalled)
{
Information("Install path: {0}", installPath);
} Which might help you understand the order in which VSWhere is detecting your installations. Of course, you also have the option to hard-code the absolute path of the MSBuild that matches your environment, but that's the less optimal solution. MSBuild("./test/Test.sln", new MSBuildSettings
{
Verbosity = Verbosity.Minimal,
Configuration = "Release",
ToolPath = @"C:\Dev\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe", // <<<
}); |
Beta Was this translation helpful? Give feedback.
-
@augustoproiete thank you for your help! Whatever I do, it doesn't work. Reinstalled Windows, installed Visual Studio 2022 Preview and cake successfully build my project. It's definitely magic... |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
@zgdump Cake expects MSBuild to be in one of the default locations based on the version you specify and the different editions that exist. In your case you're specifying
VS2019
so it would search the following locations:It seems you ha…