dotnet / installer

.NET SDK Installer
https://github.com/dotnet/sdk
1.27k stars 446 forks source link

MsBuild.Sdk.Extras fails to compile with Azure 2019 and 3.0.100-preview-010184 #662

Closed glennawatson closed 5 years ago

glennawatson commented 5 years ago

Hi,

I spoke to @onovotny (the author of MsBuild.Sdk.Extras) and he suggested opening a ticket here.

At the moment I am trying to update ReactiveUI's build scripts to use the new Azure Devops VS2019 image. This is not an issue with running locally with .NET Core 3.0 SDK installed globally.

My build script first uses the install 'dotnet 3.0 sdk' and then tries to compile. The dotnet sdk gets installed into the tools cache directory on the hosted azure host.

- task: DotNetCoreInstaller@0
    displayName: Install Dot Net Core v3.0.100-preview-010184
    inputs:
        version: '3.0.100-preview-010184'

I have the following global.json file (and tried with and without the sdk version)

{
    "sdk": {
        "version": "3.0.100-preview-010184"
    },
    "msbuild-sdks": {
        "MSBuild.Sdk.Extras": "2.0.0-preview.21"
    }
}

I get the following build errors:

Building Splat.csproj
Microsoft (R) Build Engine version 16.0.360-preview+g9781d96883 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

D:\a\1\s\src\Splat\Splat.csproj : error : C:\hostedtoolcache\windows\dncs\3.0.100-preview-010184\x64\sdk\3.0.100-preview-010184\Sdks\MSBuild.Sdk.Extras\Sdk not found. Check that a recent enough .NET Core SDK is installed and/or increase the version specified in global.json.
D:\a\1\s\src\Splat\Splat.csproj : error : C:\hostedtoolcache\windows\dncs\3.0.100-preview-010184\x64\sdk\3.0.100-preview-010184\Sdks\MSBuild.Sdk.Extras\Sdk not found. Check that a recent enough .NET Core SDK is installed and/or increase the version specified in global.json.
D:\a\1\s\src\Splat\Splat.csproj : error MSB4236: The SDK 'MSBuild.Sdk.Extras' specified could not be found.
glennawatson commented 5 years ago

As @onovotny pointed out, it seems to be searching for MSBuild.Sdk.Extras in the same directory as the hostedtoolcache rather than in the NuGet folder.

nguerrera commented 5 years ago

Are you able to check the contents of <directory of msbuild.exe>\SdkResolvers\Microsoft.Build.NuGetSdkResolver>?

There should be an xml file there like this:

<SdkResolver>
  <Path>..\..\..\..\..\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll</Path>
</SdkResolver>

Then check that the path referenced exists.

nguerrera commented 5 years ago

That said, @vatsan-madhavan saw the same symptom recently, but only sporadically and we were unable to repro it when logging into the build machine. I don't know if it was using the same image.

In that case, the resolver was definitely there and could be seen downloading packages in the binlog, but then did not log an error or resolve the sdk and it continued on to the .net core sdk resolver.

nguerrera commented 5 years ago

Setting the milestone to 3.0 just to indicate that it is triaged. This is not an issue in the SDK, but either in VS 2019 or the image that deployed it.

clairernovotny commented 5 years ago

The xml file exists and has the contents, as does the dll file:

You can see the logs here: https://dev.azure.com/onovotny/GitBuilds/_build%2Fresults?buildId=1635&_a=summary

nguerrera commented 5 years ago

Can you produce a binlog from a failing build? (As usual ensure there's no secrets in environment variables or other sensitive data that a binlog would capture before generating/sharing.)

clairernovotny commented 5 years ago

This is from the binlog:

Failed to parse "d:\a\1\s\Rx.NET\Source\global.json". Could not load file or assembly 'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The system cannot find the file specified.
nguerrera commented 5 years ago

Yep, just saw that on the email thread. Checking how it is supposed to bind.

nguerrera commented 5 years ago

In the latest bits I have, "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\NuGet\Microsoft.Build.NuGetSdkResolver.dll" references NewtonSoft.Json 9.0.0.0 as well:

.assembly extern Newtonsoft.Json
{
  .publickeytoken = (30 AD 4F E6 B2 A6 AE ED )                         // 0.O.....
  .ver 9:0:0:0
}

And NewtonSoft.Json.dll 9.0.0.0 is sitting next to it:

.assembly Newtonsoft.Json
{
  .ver 9:0:0:0
}

Can you check that the same conditions exist on the image? This may be a bug that was fixed but needs a newer VS 2019 to get on to the image.

clairernovotny commented 5 years ago

The file is there, but do you know an easy way in the CLI to get the assm version?

https://dev.azure.com/onovotny/GitBuilds/_build%2Fresults?buildId=1636&_a=summary

clairernovotny commented 5 years ago

Okay, published the contents of that directory: https://dev.azure.com/onovotny/GitBuilds/_build/results?buildId=1637&_a=summary&view=results

The version of Newtonsoft.Json appears to be version 10

nguerrera commented 5 years ago

Well, that sounds like the problem. It should match the 9.0.0.0 ref.

Looks like this was fixed by https://github.com/NuGet/NuGet.Client/pull/2713 and fixed for Preview 4

cc @rrelyea @nkolev92

nguerrera commented 5 years ago

Duplicate of NuGet/Home#7706

clairernovotny commented 5 years ago

Here's a workaround for now:

With PowerShell, either inline or as a task

iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/onovotny/UpdateVsOnAgent/master/Fix-VisualStudioPreviewNuGetSdk.ps1'))
- powershell: iex ((New-Object System.Net.WebClient).DownloadString('https://raw.githubusercontent.com/onovotny/UpdateVsOnAgent/master/Fix-VisualStudioPreviewNuGetSdk.ps1'))
  displayName: VS Preview workaround