novotnyllc / MSBuildSdkExtras

Extra properties for MSBuild SDK projects
MIT License
345 stars 43 forks source link

Azure DevOps Unable to find package MSBuild.Sdk.Extras #261

Closed robintschroeder closed 3 years ago

robintschroeder commented 3 years ago

I am trying to build a Xamarin plugin in Azure DevOps. The same project builds perfectly on my laptop. I have a brand new cloud hosted Agent Pool running windows-latest / VS2019 image, created today.

In the YAML, I am explicitly calling for msbuild:

pool:
  vmImage: 'windows-latest'
  demands: msbuild

In the project file (because I only have one project): <Project Sdk="MSBuild.Sdk.Extras/3.0.23">

In the project, I have a global.json:

{
  "sdk": {
    "version": "5.0.104"
  },
  "msbuild-sdks": {
    "MSBuild.Sdk.Extras": "3.0.23"
  }
}

I have tried a number of variations with and without the global.json, and also with different versions of the sdks. No luck.

The pipeline fails while restoring the MSBuild.Sdk.Extras nuget. I verified that C:\Program Files\dotnet\sdk\5.0.104 exists on the agent pool server, but it seems like it can't get the MSBuild.Sdk.Extras. I see the service index warning, but isn't it already connected?? Any help would be appreciated!

...
Package source with Name: NuGetOrg added successfully.
C:\hostedtoolcache\windows\NuGet\5.8.0\x64\nuget.exe restore D:\a\1\s\xxxxx\xxxxxx.sln -Verbosity Detailed -NonInteractive -ConfigFile D:\a\1\Nuget\tempNuGet_3009.config
NuGet Version: 5.8.0.6930
D:\a\1\s\xxxxx\xxxxx\xxxxxx.csproj : warning : Unable to load the service index for source https://xxxxx/xxxxxx/nuget/v3/index.json.
D:\a\1\s\xxxxx\xxxxxx.csproj : error : Unable to find package MSBuild.Sdk.Extras. No packages exist with this id in source(s): xxx
D:\a\1\s\xxxxx\xxxxxx.csproj : error : C:\Program Files\dotnet\sdk\5.0.104\Sdks\MSBuild.Sdk.Extras\Sdk not found. Check that a recent enough .NET SDK is installed and/or increase the version specified in global.json.
D:\a\1\s\xxxxx\xxxxxx.csproj : error MSB4236: The SDK 'MSBuild.Sdk.Extras/3.0.23' specified could not be found.

MSBuild auto-detection: using msbuild version '16.9.0.11203' 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.
MSBuild P2P timeout [ms]: 120000
C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\bin\msbuild.exe "C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\f4shqkhq.qb4.nugetinputs.targets" /t:GenerateRestoreGraphFile /nologo /nr:false /v:q /p:NuGetRestoreTargets="C:\Users\VssAdministrator\AppData\Local\Temp\NuGetScratch\pmcz3eip.wqj.nugetrestore.targets" /p:RestoreUseCustomAfterTargets="True" /p:RestoreTaskAssemblyFile="C:\hostedtoolcache\windows\NuGet\5.8.0\x64\nuget.exe" /p:RestoreSolutionDirectory="D:\a\1\s\xxx\\" /p:RestoreConfigFile="D:\a\1\Nuget\tempNuGet_3009.config" /p:SolutionDir="D:\a\1\s\xxx\\" /p:SolutionName="xxx"
NuGet.CommandLine.ExitCodeException: Exception of type 'NuGet.CommandLine.ExitCodeException' was thrown.
   at NuGet.CommandLine.MsBuildUtility.<GetProjectReferencesAsync>d__6.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<GetDependencyGraphSpecAsync>d__68.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at NuGet.CommandLine.RestoreCommand.<DetermineInputsFromMSBuildAsync>d__63.MoveNext()
...
clairernovotny commented 3 years ago

It looks like nuget.org isn't in the nuget.config file you have?

robintschroeder commented 3 years ago

OK - now I am embarrassed... but hopefully this post helps someone else...

Added this to my nuget.config and the pipeline finds MSBuild.Sdk.Extras just fine - duh! <add key="NuGet official package source" value="https://api.nuget.org/v3/index.json" />

shawyunz commented 3 years ago

Just ran into this when building a xamarin android project. My solution: updated the restore command in yml before building.

  - task: NuGetCommand@2
    displayName: 'NuGet restore'
    inputs:
      command: 'restore'
      restoreSolution: '$(RestoreSolution)'
      feedsToUse: 'config'

  - task: VSBuild@1
    displayName: 'Build Droid'
    ...
kvpt commented 3 years ago

Something has changed recently in either Net5.0 SDK or MSBuild 16.9. Now it only check for the first nuget source and fail after that if the sdk is not present in this source. In my Azure DevOps the first source seems to be "Microsoft Visual Studio Offline Package" which of course doesn't contain the SDK. Adding a step to remove this source before nuget restore fixed the issue for me.


 - script: dotnet nuget remove source "Microsoft Visual Studio Offline Packages"
joer33304 commented 2 years ago

None of the above works for me. Can somebody please post a working yaml ?

tomspilman commented 2 years ago

FYI.

I came across this thread after having the same issue with Xamarin and VS2022 on my local PC.

The fix that worked was changing my project from <Project Sdk="MSBuild.Sdk.Extras"> to <Project Sdk="MSBuild.Sdk.Extras/3.0.23">.