Nuget package source setup - visual-studio

I created a new solution and disabled nuget.org as my package source. I have different repositories added and all my packages are installed from there. On the build server I got an error:
Unable to load the service index for source https://api.nuget.org/v3/index.json.
An error occurred while sending.
the request. Unable to connect to the remote server.
A connection attempt failed because the connected party did not properly respond
after a period of time
It is because my company blocked Nuget, BUT I should not have any package from that repo.
Does somebody know where I can check if my package is from nuget.org (maybe I made mistake and download from the wrong source) or where to disable in solution/ NuGet that source permanently?

Nuget package source setup
Since you are disable nuget.org as package source for your solution, so you should also disable it by the disabledPackageSources on the build server:
Go to the folder on your build server C:\Users\<Username>\AppData\Roaming\NuGet\NuGet.Config, add following to that file:
<disabledPackageSources>
<add key="nuget.org" value="true" />
</disabledPackageSources>
Besides, if you are using TFS/VSTS to restore the nuget package, you can disable it from definition:

Related

Visual studio 2019: Adding, Updating or Deleting Package Source Has No Effect

I had a package source named MyMyGetFeed, I changed its URL but it still looking at the old one, even after deleting it I can still see that visual studio is looking into it as shown in the error message below, I'd also tried to create new package source with the new URL and it is still showing the same error neglegting my new source. Cleaning project, restarting Visual Studio and even deleting NuGet.Config file didn't help. Any Ideas please?
Severity Code Description Project File Line Suppression State
Error NU1102 Unable to find package Synergix.WE.Security.Cryptography with version (>= 2.1.3)
- Found 3 version(s) in MyMyGetFeed [ Nearest version: 2.1.2 ]
- Found 0 version(s) in nuget.org Synergix.ADCE.Client.Service.Commands C:\Users\MOHAMMAD\source\repos\adce.client\src\Service\Synergix.ADCE.Client.Service.Commands\Synergix.ADCE.Client.Service.Commands.csproj 1
Visual studio 2019: Adding, Updating or Deleting Package Source Has No
Effect
First, if you add the new package source by Tools-->Options-->Nuget Package Manager-->Package Sources(global nuget.config file), you should make sure that there is no other custom nuget.config in your solution explorer to affect the global nuget.config file. See this.
Besides, you can follow the below steps to troubleshoot your issue:
you should make sure that the new package source url is enable and the old package source url is deleted or unchecked like this:
In global nuget.config file(C:\Users\<User>\AppData\Roaming\NuGet\) like this:
<packageSources>
<add key="new package source" value="C:\xxxxxx" />
<add key="old package source" value="C:\xxxxxxx" />
</packageSources>
<disabledPackageSources>
<add key="old package source" value="true" />
</disabledPackageSources>
From the error message, it searches for version 2.1.3, so make sure that Synergix.WE.Security.Cryptography 2.1.3 is in the new package source url and you have the right to access the new package source. To test it, you can copy the link in website to see whether it can return any request.
clean nuget caches under Tools-->Options-->Nuget Package Manager-->General-->Clear All Nuget Caches or just delete the packages folder under C:\Users\xxxx\.nuget.
And run nuget locals all -clear under Tools-->Nuget Package Manager-->Package Manager Console
disable any third party extensions under Extensions-->Manage Extensions in case it causes this abnormal behavior.
close VS instance, delete .vs hidden folder, bin, obj folder, 'Nuget.Config' file under C:\Users\<User>\AppData\Roaming\NuGet\(will recreate automatically when restart VS)
and then run VS as administrator to test whether the issue persists.
In addition, try to create a new default project and then install this package to test whether the issue is your project itself or is the nuget tool.

How to disable "transitive package management" for a Visual Studio project

How do I disable "transitive package management"?
I wish to do so, so that I can install a package that I "packed" locally and have in a .nupkg file. When I attempt to do so, I get a messaging stating that The 'Source' parameter is not respected for the transitive package management based project(s) {csproj file}. The enabled sources in your NuGet configuration will be used.
Complete Context
When developing a NuGet package that's not ready for distribution via our NuGet feed, I often create a local .nupkg file like this from the package manager console:
nuget pack {path-to-csproj-file}
This generates a {project-name}.nupkg file, which I can then install in another project by opening it in Visual Studio, navigating to the package manager console, and entering the command
Install-Package {path-to-nupkg-file}
This has worked great and once the NuGet package is ready for distribution, we push it up to Azure DevOps and let the build pipeline there push it into our feed.
However, I just recently inherited a project where the prior developer apparently setup "transitive package management" that prevents this workflow. Here's what I get when I try to install directly from a .nupkg file:
Install-Package C:\Users\Josh\source\repos\SpeakerDiscountManager\SpeakerDiscountData.1.0.5.nupkg
The 'Source' parameter is not respected for the transitive package management based project(s) MembershipApplicationWidget\MembershipApplicationWidget.csproj. The enabled sources in your NuGet configuration will be used.
<snipped several lines of unsuccessfully searching configured package sources>
Install-Package : NU1102: Unable to find package SpeakerDiscountData with version (>= 1.0.5)
Obviously, it doesn't find the package I've specified via file, because it is searching online feeds and it doesn't exist in any of our online package sources--the package is in a testing state, not ready for anyone to use but me.
Based on the error message, I need to turn off "transitive package management" so that I can specify a file source for the package, but I've been unable to turn up any information online about how this is configured.
I did try installing this exact same .nupkg file in another project, using the same Install-Package {path-to-nupkg-file} procedure. This works.
How to disable “transitive package management” for a Visual Studio
project
I think this problem transitive package management is related to your current project structure which has some intricate dependencies, custom rules and so on. Therefore, turning off transitive package management is unpractical. If you create other projects and then install this package by your way, I think it probably will not occur.
As a best workaround, as you said(hint from the message The enabled sources in your NuGet configuration will be used.), add the the local nuget package's path into Nuget Package Source.
In your side, I think you specify -Source xxxxx(the path of the nuget package) to install this package in the package manager console, if so, this function actually is inconvenient.
You can just add the folder path which SpeakerDiscountData.1.0.5.nupkg exists into global nuget package source. Once you have done it, it will applies to any projects in this machine.
It has two ways:
1) VS IDE UI
Tools-->Options-->NuGet Package Manager-->Packages Sources-->add a new key and input the path of the nuget folder. Also, check its option.
2) global NuGet.Config file
(C:\Users\xxxx\AppData\Roaming\NuGet\Nuget.Config and step 1 is just add the path into this file by VS UI Control)
add these:
<packageSources>
<add key="Local Packages Source" value="C:\Users\Josh\source\repos\SpeakerDiscountManager\" />
..........
</packageSources>
After that, you can use your command to install this nuget package.
Note: If the root directory of your solution also has a file named nuget.config, the parameters in it will override the global file. It has the highest priority.
Just go to Vs IDE Tools/Nuget Package Manager/Package Manager Setting And Check The address of Package Sources.
it's something like "C:\Program Files (x86)\Microsoft SDKs\NuGetPackages".
Then Copy your package file into that folder and at last run this command in Package Manager Console:
install-package packagename

Nuget Packages are not found in nexus repo

I am using nexus OSS 3.15.2-01 and its new instance.
Issue we are facing is with nuget proxy repos, if i try it manually curl nuget org on nexus server it reaches the URL. but when i try to download it from VS or from cmd it says file not found.
I have created a seperate blob for nuget and new repo nuget_gallery, and provided the nuget org in proxy configuring it but its not working
From VS it says,
Severity Code Description Project File Line Suppression State
Error The feed ‘nexus prod [repo URL]’ lists package ‘Microsoft.AspNet.WebApi.Client.5.2.7’ but multiple attempts to download the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in progress. Verify the package exists on the feed and try again.
Unable to find package ‘Microsoft.AspNet.WebApi.Client.5.2.7’.
How ever the version is fetched in nexus if we browse the repo but even when we try to download it says file not found (0 bytes)
Bit late to the party, but I had this same problem. It seems to be down to lack of NuGet protocol 3 support in Nexus.
Workaround was to add protocolVersion="2" to my nuget.config like this;
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />
<add key="your-nexus-repo" value="http://your-nexus-repo/nexus/service/local/nuget/your-repo-name/" protocolVersion="2"/>
</packageSources>
</configuration>
I still had problems with dotnet core 3 packages, so also had to add back nuget.org (or remove <clear/> if nuget.org is in your global config)
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
You can try tips below to check if it helps:
1.Clean all the NuGet package cache by the command line: nuget locals all -clear.
2.Close all Visual Studio instance, then delete nuget.config file in the location: C:\Users\xxx\AppData\Roaming\NuGet\NuGet.Config, then re-open the Visual Studio to restore nuget packages.
3.Check if there is a firewall policy or other proxy settings that block the nuget installation package.
And please check if the issue only occurs when featching packages from Nexus or it also occurs when you download packages from nuget.org. Maybe you can get some help from this thread.

Default package source for NuGet defaulting to newly added source and not All or nuget.org

I added a NuGet 'Package source' to Visual Studio since we have an internal server at work.
Visual Studio now always defaults to my internal server and cannot find most of our NuGet packages until I switch the package source to All or nuget.org.
This is a minor inconvenience, but for the past few weeks, I have been doing many more clicks every time I need to work with the NuGet package manager. Can anyone tell me how to default to All instead of having it always default to Internal nuget?
Can anyone tell me how to default to All instead of having it always default to Internal nuget?
To my knowledge, the default package source of NuGet Package Manager depends on the order of package source and the property of activePackageSource in nuget.config.
The order of package source:
When you open NuGet Package Manager setting, Tools->Options->NuGet Packager Manager->Package Source, you will notice that there are up and down arrows for package source:
NuGet Package Manager will give priority for default NuGet package source in the top of the package source list. For example, if I set NuGet package source LocalServer at the top of that list, when I create a new project, the default NuGet source will be changed to LocalServer:
However, this priority of default NuGet source can easily be broken by the property of activePackageSource in nuget.config.
Open the nuget.config file from %appdata%\NuGet\NuGet.config, add the following code:
<activePackageSource>
<add key="LocalServer2" value="D:\LocalServerTest" />
</activePackageSource>
Restart Visual Studio, then create a new project, you will find the default NuGet source change to the LocalServer2:
So, if you want to default nuget.org instead of having it always default to Internal nuget, you can set the NuGet source nuget.org at top of NuGet source list or set the nuget.org as activePackageSource in the nuget.config:
<activePackageSource>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</activePackageSource>
Update for comment:
Is there no way to default to All? Maybe you can suggest defaulting to All (looks like you work for MS)
if you want to set the default NuGet source to All, you can use the setting below in nuget.config:
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>

Task for a Bamboo Build plan fails when trying to get information from packages

I am trying to run an MSBuild task in atlassian bamboo for a test run of a Bamboo plan on my local device. I have created the plan and it will retrieve the code from Github successfully, as well as being successfully running the default scoure control checkout.
The first problem I have is that the system will fail because the MSBuild task cannot get the referenced files. So when I looked into the Manage Nuget Packages, It says some of the packages are missing, and when I click Restore most of them restore but some of them have errors.
I think the main reason is because of this package Microsoft.CodeDom.Providers.DotNetCompilerPlatform -Version 1.0.0 is not being installed correctly. The error message says that it is because the path, file name or both are too long, but I have not named anything the project is already build and running successfully from Github. I have tried to install as well by using the Package Manager Console but I get the same result. I also tried creating the folders that it said the file was meant to be located but this is not working either.
I think that the problem is that the package is not found during package restore so I tried to add a NuGet.config file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
</configuration>
But this is not working how can I fix this?
According to the error message screenshot, the mentioned package "Carfinance.Authorization.Core.Mvc" is not found in nuget.org site. Please make sure this package's source URL has added into your Visual Studio NuGet Package Manager Source list (Tools -> Options -> NuGet Package Manager -> Package sources).
And please add the node in the global NuGet.Config file which stored in C:\Users\UserName\AppData\Roaming\NuGet folder. After change the config file, please remember restarting your Visual Studio.
For the Microsoft.CodeDom.Providers.DotNetCompilerPlatform path too long issue, please make sure the stored path folder is not too long. You could create a new project and store it on desktop and install this packages to check whether it could be install correctly. Then please copy your current project on desktop too, it could make sure its stored path will not too long.

Resources