Cake NuGetRestore always wants MSBuild14?

When I try to install a build solution using Cake v0.19.1 on a machine that only ever knew Visual Studio 2017, I cannot get NuGetRestoreto accept the parameter MSBuildVersion = NuGetMSBuildVersion.MSBuild15.

Is there any magic step to getting a specific version of MSBuild in NuGetRestorethat I am missing?

Exit

...

========================================
RestoreNuGet
========================================
Executing task: RestoreNuGet
Failed to load msbuild Toolset
  Could not load file or assembly 'Microsoft.Build, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
An error occurred when executing task 'RestoreNuGet'.
Error: NuGet: Process returned an error (exit code 1).

Trimmed-down build.cake

var target = Argument("target", "Default");
var solution = "./some-random.sln";

Task("Default")
.Does(() => {
    NuGetRestore(
        solution,
        new NuGetRestoreSettings {
            MSBuildVersion = NuGetMSBuildVersion.MSBuild15,
        }
    );
});

RunTarget(target);

Update: getting NuGet v4

Per @devlead answer , I pointed the build.ps1 file to v4.0.0 from NuGet and got this output.

Cannot find the specified version of msbuild: '15'
An error occurred when executing task 'RestoreNuGet'.
Error: NuGet: Process returned an error (exit code 1).

In my complete build.cake, I use vswherefor later MSBuildSettings, which I can get to unload the found MSBuild path (and I confirmed that exe exists in Explorer).

C:/Program Files (x86)/Microsoft Visual Studio/2017/Enterprise/MSBuild/15.0/Bin/amd64/MSBuild.exe
+6
2

- MSBuild , MSBuild NuGet.

MSBuild(
    "./some.sln",
    configurator => configurator.WithTarget("restore"));
+3

, NuGet.exe, v4.0.0, , https://dist.nuget.org

build.ps1, , NuGet.exe

, Test.Path - nuget.exe, - , . uri, ( v3.5.0), build.ps1,

$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/latest/nuget.exe"

to

$NUGET_URL = "https://dist.nuget.org/win-x86-commandline/v4.0.0/nuget.exe"

, v4.0.0 exe.

PowerShell ,

if ((Get-ChildItem $NUGET_EXE `
    | % VersionInfo `
    | % ProductVersion `
    | ? { $_ -eq '4.0.0' }|Measure-Object).Count -eq 1)
{
   'Correct version'
} else {
   'Incorrect version'
}
+2

Source: https://habr.com/ru/post/1016188/


All Articles