dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.23k stars 1.35k forks source link

Struggled to get Preview4 building in AzDops #4339

Open gregpakes opened 5 years ago

gregpakes commented 5 years ago

I have been asked to submit my issue here by @rainersigwald

Original Tweet: https://twitter.com/gregpakes/status/1122672235439804416

Background

I am porting a tiny WCF application to Asp.Net Core 3.0 Preview 4. After port, it is a a basic Asp.Net Core Web Api with a database project (sqlproj). Here are the issues I encountered:

error MSB4019: The imported project "/opt/hostedtoolcache/dncs/3.0.100-preview4-011223/x64/sdk/3.0.100-preview4-011223/Microsoft/VisualStudio/v11.0/SSDT/Microsoft.Data.Tools.Schema.SqlTasks.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.

Error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.

and

Error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.

error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\MSTest.TestAdapter.2.0.0-beta4\build\net45\MSTest.TestAdapter.props.

[command]C:\hostedtoolcache\windows\NuGet\5.0.0\x64\nuget.exe sources Add -NonInteractive -Name NuGetOrg -Source https://api.nuget.org/v3/index.json -ConfigFile d:\a\1\Nuget\tempNuGet_24152.config
Package source with Name: NuGetOrg added successfully.
[command]C:\hostedtoolcache\windows\NuGet\5.0.0\x64\nuget.exe restore d:\a\1\s\iSAMS.Mobile.sln -Verbosity Detailed -NonInteractive -ConfigFile d:\a\1\Nuget\tempNuGet_24152.config
d:\a\1\s\iSAMS.Mobile.Api\iSAMS.Mobile.Api.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
NuGet Version: 5.0.0.5923
d:\a\1\s\iSAMS.Mobile.Api\iSAMS.Mobile.Api.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
MSBuild auto-detection: using msbuild version '16.0.461.62831' from 'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin'. Use option -MSBuildVersion to force nuget to use a specific version of MSBuild.
d:\a\1\s\iSAMS.Mobile.Api.Tests\iSAMS.Mobile.Api.Tests.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
MSBuild P2P timeout [ms]: 120000
d:\a\1\s\iSAMS.Mobile.Api.IntegrationTests\iSAMS.Mobile.Api.IntegrationTests.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk.Web' specified could not be found.
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\o513ajfj.g4g.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\vhcrbbfv.v00.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\5.0.0\x64\nuget.exe" /p:RestoreSolutionDirectory="d:\a\1\s\\" /p:RestoreConfigFile="d:\a\1\Nuget\tempNuGet_24152.config" /p:SolutionDir="d:\a\1\s\\" /p:SolutionName="iSAMS.Mobile"
d:\a\1\s\iSAMS.Mobile.Legacy\iSAMS.Mobile.Legacy.csproj : error : Unable to locate the .NET Core SDK. Check that it is installed and that the version specified in global.json (if any) matches the installed version.
NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
d:\a\1\s\iSAMS.Mobile.Legacy\iSAMS.Mobile.Legacy.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.
   at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
Error NETSDK1045: The current .NET SDK does not support targeting .NET Core 3.0.  Either target .NET Core 2.2 or lower, or use a version of the .NET SDK that supports .NET Core 3.0.

Apologies for the long rambling post. I'm sure a lot of this is due to my unfamiliarity with the new bits, but I was asked to post... so I hope it helps.

rainersigwald commented 5 years ago

Thanks! Some of these things are expected behavior, but we could definitely do a better job of improving errors and user experience.

  1. dotnet build can't build .sqlproj, because the targets for doing so are distributed with VS instead of as an SDK or NuGet package.
  2. Non-prerelease versions of Visual Studio (and MSBuild.exe) don't find prerelease versions of the .NET Core SDK. (Maybe we could sidestep this when using the Azure Pipelines .NET Core Tool Installer task somehow? The user explicitly opted in in that scenario)
  3. dotnet restore can only restore for the projects that it can understand.
  4. nuget.exe restore is subject to the same constraints as msbuild.exe.

Some things surprise me and need further investigation:

  1. What's the difference between x86 and amd64 MSBuild finding the SDK? That shouldn't be relevant.
  2. Can we produce better errors or guiderails in any of these situations?

fyi @kathleendollard -- here's a (bad) early-adopter scenario story.

KathleenDollard commented 5 years ago

@rainersigwald how many of these things are in process for resolution? Do some need to be handed off to other teams?

netcorefactory commented 5 years ago

This worked for me: `- task: DotNetCoreInstaller@0 displayName: 'Install .net core 3.0 (preview)' inputs: packageType: 'sdk' version: '3.0.100-preview6-012264' includePreviewVersions: true installationPath: $(Agent.ToolsDirectory)/dotnet

and the global.json

{ "sdk": { "version": "3.0.100-preview6-012264" } }