Restoring dependencies in Visual Studio Code is using the wrong source/feed
I think VS Code is just running a dotnet restore
, and the reason you're seeing this source being used is because it's configured in your User/Computer nuget configuration file (located on windows, which you seem to be running, at %appdata%\NuGet\NuGet.Config
& %ProgramFiles(x86)%\NuGet\Config
respectively). The VS configuration editor you showed is just a nice GUI for this configuration file.
If you want to keep this general setting, you should be able to use a nuget.config
file in your VS Code project (which you mentioned you don't have at the moment). There is more info on this here -Add custom package source to Visual Studio Code.
Also, if you're trying to restore manually, you can use one of these 2 flags -
dotnet restore --source https://api.nuget.org/v3/index.json
dotnet restore --ignore-failed-sources
These are pretty self explanatory, but you can see the full documentation here - https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x
Hope this helps (:
Konzy262
Updated on June 13, 2022Comments
-
Konzy262 almost 2 years
I'm not sure how to set the default nuget feed for my .net core project in Visual Studio Code to https://api.nuget.org/v3/index.json
When I attempt to add a package (and subsequently, restore dependencies), I get the following errors...
C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Unable to load the service index for source https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json. [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj] C:\Program Files\dotnet\sdk\2.1.403\NuGet.targets(114,5): error : Response status code does not indicate success: 401 (Unauthorized). [c:\Users\Matthew.OConnor\Desktop\Important Documents\Programming\DatingApp\DatingApp.API\DatingApp.API.csproj]
This source
https://smartassessor.pkgs.visualstudio.com/_packaging/SANuget/nuget/v3/index.json
has nothing to do with my current project, however it is used for other projects that are typically run using full blown Visual Studio. Those projects are saved in a completely different place to this project.I simply want to be able to add nuget packages from nuget.org in my .net core project. How do I do this in VS code?
I don't currently have a nuget.config file in this project.
The package source mentioned in the error appears to be coming from a package source I have setup whilst using Visual Studio
This is my csproj file...
<Project Sdk="Microsoft.NET.Sdk.Web"> <PropertyGroup> <TargetFramework>netcoreapp2.1</TargetFramework> </PropertyGroup> <ItemGroup> <Folder Include="wwwroot\"/> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.AspNetCore.App"/> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4"/> <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="4.0.1"/> <PackageReference Include="CloudinaryDotNet" Version="1.3.1"/> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.1.0-preview1-final"/> </ItemGroup> </Project>
CloudinaryDotNet
is the package that generated the errors above. -
Dilip about 5 yearsAwesome, you made my day. Thanks