Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restoring dependencies in Visual Studio Code is using the wrong source/feed

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

enter image description here

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.

like image 701
Konzy262 Avatar asked Oct 20 '18 18:10

Konzy262


People also ask

How do I restore references in Visual Studio?

Restore by using MSBuild You can use msbuild -t:restore to restore packages in NuGet 4. x+ and MSBuild 15.1+, which are included with Visual Studio 2017 and higher. This command restores packages in projects that use PackageReference for package references.

How do I force a NuGet package to restore?

Restore NuGet packagesNavigate to Tools > Options > NuGet Package Manager > General, and then select the Allow NuGet to download missing packages check box under Package Restore. Enabling Restore NuGet Packages. In Solution Explorer, right-click the solution, and then select Restore NuGet Packages.

How do I fix nu1101?

Solution. Examine the project's dependencies in Visual Studio to be sure you're using the correct package identifier and version number. Also check that the NuGet configuration identifies the package sources you are expected to be using. If you use packages that have Semantic Versioning 2.0.

How do I update Visual Studio dependencies?

In VS IDE: Right-click project name in Solution Explorer => Manage Nuget Packages , in Updates lab you can choose Select all packages and Update Button.


1 Answers

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://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-restore?tabs=netcore2x

Hope this helps (:

like image 160
Nimrod Dolev Avatar answered Nov 14 '22 22:11

Nimrod Dolev