Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] dotnet restore failed when api.nuget.org is blocked in firewall and custom feed is provided #558

Open
JohanSpannare opened this issue Apr 19, 2024 · 1 comment

Comments

@JohanSpannare
Copy link

JohanSpannare commented Apr 19, 2024

Background

We are running Azure DevOps Server on-prem. And for security reason we are not allowing internet access from our build agents. Instead all agents are configured to use internal nuget feeds configured in Artifactory mirroring nuget.org.

In below example i have disabled the access to api.nuget.org on my local laptop. This is being able to reproduce the error locally.

Example

nuget sources

Registered Sources:
  1.  nuget.org [Enabled]
      https://artifactory.XXXX.com/artifactory/api/nuget/nuget.remote/

dotnet build

MSBuild version 17.9.4+90725d08d for .NET
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error : Could not resolve SDK "Microsoft.VisualStudio.JavaScript.Sdk". Exactly one of the probing messages below indicates why we could not r
esolve the SDK. Investigate and resolve that message to correctly specify the SDK.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" returned null.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   Unable to find package Microsoft.VisualStudio.JavaScript.Sdk. No packages exist with this id in source(s): nuget.org
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.VisualStudio.JavaScript.Sdk" because directory "C:\Program Files
\dotnet\sdk\8.0.200\Sdks\Microsoft.VisualStudio.JavaScript.Sdk\Sdk" did not exist.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : warning : Unable to load the service index for source https://api.nuget.org/v3/index.json.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : warning NU1503: Skipping restore for project 'C:\repo\CST.Klas\cst.klas\cst.klas.esproj'. The project file may be invalid or missing targets
required for restore. [C:\repo\CST.Klas\CST.Klas.sln]
  Determining projects to restore...
  All projects are up-to-date for restore.

Build FAILED.

C:\repo\CST.Klas\cst.klas\cst.klas.esproj : warning : Unable to load the service index for source https://api.nuget.org/v3/index.json.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : warning NU1503: Skipping restore for project 'C:\repo\CST.Klas\cst.klas\cst.klas.esproj'. The project file may be invalid or missing targets
required for restore. [C:\repo\CST.Klas\CST.Klas.sln]
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error : Could not resolve SDK "Microsoft.VisualStudio.JavaScript.Sdk". Exactly one of the probing messages below indicates why we could not r
esolve the SDK. Investigate and resolve that message to correctly specify the SDK.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   SDK resolver "Microsoft.DotNet.MSBuildWorkloadSdkResolver" returned null.
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   Unable to find package Microsoft.VisualStudio.JavaScript.Sdk. No packages exist with this id in source(s): nuget.org
C:\repo\CST.Klas\cst.klas\cst.klas.esproj : error :   MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.VisualStudio.JavaScript.Sdk" because directory "C:\Program Files
\dotnet\sdk\8.0.200\Sdks\Microsoft.VisualStudio.JavaScript.Sdk\Sdk" did not exist.
    2 Warning(s)
    1 Error(s)

Time Elapsed 00:00:18.24

Expected result

I expect that any nuget feed configured should be used when resolving SDK´s as well for custom nuget packages.

MSBuild version 17.9.4+90725d08d for .NET
  Determining projects to restore...
  All projects are up-to-date for restore.
  CST.API.Motor.Klas -> C:\repo\CST.Klas\CST.API.Motor.Klas\bin\Debug\net8.0\CST.API.Motor.Klas.dll

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:03.10

Work around

To get around this error, i manually have to preload the nuget cache. This so when MSBuildSdks is trying to resolve and dependencies. It do not need to go externally to download the package via api.nuget.org that is blocked.

mkdir ./dummy;
cd ./dummy;
dotnet new classlib;
dotnet add package Microsoft.VisualStudio.JavaScript.Sdk -s https://artifactory.XXXX.com/artifactory/api/nuget/nuget.remote/


$latestVersion= (Get-ChildItem ~\.nuget\packages\microsoft.visualstudio.javascript.sdk\ -Directory | Sort-Object -Descending)[0].FullName
$latestSDKVersion = (Get-ChildItem 'C:\Program Files\dotnet\sdk\' -Directory |Where-Object -Property name -Match "8."|  Sort-Object -Descending)[0].FullName

cp $latestVersion $latestSDKVersion\sdks\microsoft.visualstudio.javascript.sdk\ -Recurse -Force -ErrorAction Ignore
@JohanSpannare
Copy link
Author

@jeffkl

@JohanSpannare JohanSpannare changed the title dotnet restore failed when api.nuget.org is blocked in firewall and custom feed is provided [BUG] dotnet restore failed when api.nuget.org is blocked in firewall and custom feed is provided Apr 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant