microsoft / azure-pipelines-tasks

Tasks for Azure Pipelines
https://aka.ms/tfbuild
MIT License
3.46k stars 2.6k forks source link

DotNetCoreCLI@2 restore broken for custom MsBuild SDKs #10498

Closed Daniel-Khodabakhsh closed 5 years ago

Daniel-Khodabakhsh commented 5 years ago

Required Information

Type: Bug

Task Name: DotNetCoreCLI@2

Environment

Issue Description

In Azure DevOps, DotNetCoreCLI@2 restore cannot restore my custom SDK in my company's NuGet stream.

This issue does not occur for nuget packages I reference via <PackageReference />, nor does it occur in Visual Studio, nor does it occur when I run dotnet restore locally (had to manually install https://github.com/Microsoft/artifacts-credprovider though).

The error I'm getting in Azure DevOps is:

[command]/opt/hostedtoolcache/dncs/2.2.102/x64/dotnet restore /home/vsts/work/1/s/src/App/App.csproj --configfile /home/vsts/work/1/Nuget/tempNuGet_62250.config --verbosity Detailed
Build started 5/23/19 11:35:31 PM.
     0>Resolving SDK 'xxx.Sdk.App'...
       Running restore with 2 concurrent jobs.
       Reading project file /home/vsts/work/1/s/src/App/App.csproj.
       Restoring packages for /home/vsts/work/1/s/src/App/App.csproj...
       Restoring packages for .NETStandard,Version=v0.0...
         GET https://api.nuget.org/v3-flatcontainer/xxx.sdk.app/index.json
         NotFound https://api.nuget.org/v3-flatcontainer/xxx.sdk.app/index.json 128ms
       Resolving conflicts for .NETStandard,Version=v0.0...
     0>/home/vsts/work/1/s/src/App/App.csproj : warning : Unable to load the service index for source https://xxx.pkgs.visualstudio.com/_packaging/Production/nuget/v3/index.json.
     0>/home/vsts/work/1/s/src/App/App.csproj : warning : Unable to load the service index for source https://xxx.pkgs.visualstudio.com/_packaging/PreRelease/nuget/v3/index.json.
     0>/home/vsts/work/1/s/src/App/App.csproj : warning : Unable to load the service index for source https://xxx.pkgs.visualstudio.com/_packaging/DevFeeds/nuget/v3/index.json.
     0>/home/vsts/work/1/s/src/App/App.csproj : error : Unable to find package xxx.Sdk.App. No packages exist with this id in source(s): nuget.org, DevFeeds, Production, PreRelease
       MSB4236: The SDK 'xxx.Sdk.App' specified could not be found.
       MSB4236: The SDK 'xxx.Sdk.App' specified could not be found.
       The target "BeforeBuild" listed in a BeforeTargets attribute at "/home/vsts/work/1/s/src/App/App.csproj (34,37)" does not exist in the project, and will be ignored.
     1>Project "/home/vsts/work/1/s/src/App/App.csproj" on node 1 (Restore target(s)).
     1>Building with tools version "15.0".
       Target "Restore" skipped. The target does not exist in the project and SkipNonexistentTargets is set to true.
     1>Done Building Project "/home/vsts/work/1/s/src/App/App.csproj" (Restore target(s)).

The SDK is added via App.csproj's tag:

<Project Sdk="xxx.Sdk.App">
  ...
</Project>

The version is specified in global.json. The issue still occurs if I specify it in the tag.

{
  "sdk": {
    "version": "2.2.102"
  },
  "msbuild-sdks": {
    "xxx.Sdk.App": "0.1.0-initial0008"
  }
}

The Azure DevOps task I use is:

  - task: DotNetCoreCLI@2
    displayName: Restore
    inputs:
      command: restore
      projects: $(Projects)
      feedsToUse: config
      nugetConfigPath: NuGet.config

My NuGet.config located at the repo root is:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="Production" value="https://xxx.pkgs.visualstudio.com/_packaging/Production/nuget/v3/index.json" />
    <add key="PreRelease" value="https://xxx.pkgs.visualstudio.com/_packaging/PreRelease/nuget/v3/index.json" />
    <add key="DevFeeds" value="https://xxx.pkgs.visualstudio.com/_packaging/DevFeeds/nuget/v3/index.json" />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>
sachinma commented 5 years ago

@infin8x can you help with this issue?

infin8x commented 5 years ago

Assigning to @elbatk for triage

Daniel-Khodabakhsh commented 5 years ago

Did some further investigation and found that this is actually a NuGet/dotnet-cli issue. Was able to locally recreate the exact same issue Azure DevOps was reporting. I created bug https://github.com/NuGet/Home/issues/8183 with more details.

Daniel-Khodabakhsh commented 5 years ago

I found a fix for this, will create a pull request.

Daniel-Khodabakhsh commented 5 years ago

Fixed in https://github.com/microsoft/azure-pipelines-tasks/issues/10567

hcoona commented 3 months ago

It failed to build in 2.238.1 again.