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

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>

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 change the NuGet-package reference in a Visual Studio project to use Nuget.config

I have a Visual Studio project file with the extension .csproj. Inside it are references like this:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props"....
I have now made a NuGet.config file in the parent folder of from the solution folder. And I removed the local "packages" folder. In the new nuget.config I set up a common location for storing packages.
nuget.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<add key="repositoryPath" value="D:\Data\NuGet" />
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
</configuration>
When I building I now get this error:
This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information...
The missing file is ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props.
How can I solve this?
If I manually have to replace the (Import Project="..\packages...) elements in the project file, what should I change it to, so that it follows the configuration from the Nuget.config?
If I manually have to replace the (Import Project="..\packages...)
elements in the project file, what should I change it to, so that it
follows the configuration from the Nuget.config?
Since you use the new nuget.config file which changed the path of the local nuget reference(like this <add key="repositoryPath" value="xxxxxx" />).
And Restore will only restore the missing nuget packages but will not change to use the new nuget package location in xxx.csproj.
So you can follow my steps to resolve the issue:
Solution
1) Tools-->Nuget Package Manager-->Package Manager Console-->
type Update-Package -reinstall to reinstall these packages to reference the new right path.
2) enter the xxxx.csproj file, delete these duplicate, old import info like these:
<Import Project="..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props" Condition="Exists('..\..\..\..\..\..\installed_packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" />
<Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
3) Then rebuild your project and will solve this issue.
Update 1
The new Nuget.config file will specify that the newly installed nuget packages use the new reference address, but for previously installed nuget packages, the reference address in the xxx.csporj file will remain the old address. The Restore procedure only restores the nuget package under the new path, but it does not make any changes to the nuget reference in xxx.csproj file, so it can only be reinstalled.
Besides, the import node is created by Microsoft.Net.Compilers props file from the build folder in the microsoft.net.compilersnuget package. And it is a nuget mechanism which can do some operation in xxx.csproj file when you install the nuget package.
However, this file is also special and when you change the nuget reference path.
Because nuget enabled the new address mechanism, during the uninstallation process, the old address of Microsoft.Net.Compilers.props is still not recognized, so it cannot be uninstalled. In fact, when you execute the reinstall nuget package, a new address has been created in the xxx.csproj file. See this:
So you should just delete duplicate files from the old address.
Visual Studio option to change the Nuget Package References
In Visual Studio Tools=> Nuget Package Manager => Package Sources.
You can change the package sources here.

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.

how to fix ChakraCore NuGet package error?

When initializing a new React Native Windows WPF project, this error happens:
NuGet Package restore failed for project Native: Unable to find version '1.4.1-preview-00010-42060' of package 'Microsoft.ChakraCore'.
https://www.myget.org/F/chakracore-preview/api/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://www.myget.org/F/chakracore-preview/api/v3/index.json'.
https://api.nuget.org/v3/index.json: Package 'Microsoft.ChakraCore.1.4.1-preview-00010-42060' is not found on source 'https://api.nuget.org/v3/index.json'.
If I create a standalone project and add the same NuGet package reference, I get the same error -- even on Xamarin Studio Mac.
The problem is that the project was referencing the "preview" feed on myget.org, instead of the official release feed on nuget.org. In the NuGet.Config file(s) in your project, remove line that references the preview feed that looks like this:
<add key="ChakraCore" value="https://www.myget.org/F/chakracore-preview/api/v3/index.json" />
In the Visual Studio 2015 (or Xamarin/Visual Studio Mac) project, right-click on the project and select Manage NuGet References. From there, you can click on the Updates tab, select ChakraCore from the list, and click "Update". This should update the packages.config and other files for you. Note that if you had the project open while editing the config files you'll need to close and re-open the project to get the new settings to take hold. In some cases, the upgrade may leave behind the reference to the previous 1.4.1-preview package and you'll need to hand-edit the csproj file to get rid of it.
If you need to make this change without Visual/Xamarin Studio, you just have to edit a few text files. In the packages.config (in Visual Studio 2015), change the line referencing the 1.4.1-preview version to the latest release (1.5.2 as of this writing):
<package id="Microsoft.ChakraCore" version="1.4.1-preview-00010-42060" targetFramework="net46" developmentDependency="true" />
becomes
<package id="Microsoft.ChakraCore" version="1.5.2" targetFramework="net46" developmentDependency="true" />
In your project's csproj file:
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" />
becomes
<Import Project="$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props" Condition="Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" />
and
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.4.1\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
becomes
<Error Condition="!Exists('$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\packages\Microsoft.ChakraCore.1.5.2\build\netstandard1.0\Microsoft.ChakraCore.props'))" />
Generally speaking, don't reference preview packages from myget.org in production projects or project templates others will use. They can be removed at any time, and security updates may not be published there with the same regularity as official channels.
Looks like the preview Microsoft.ChakraCore NuGet package was removed from the MyGet feed.
The main NuGet.org site only has stable releases for the Microsoft.ChakraCore NuGet package.
So you are left with editing any references to the package and using a published version. Microsoft.ChakraCore version 1.4.4 should work.
There is also an open issue about this on the React native GitHub site.

How should I tell TeamCity's NuGet Installer build step to use both NuGet.org and the TeamCity provided packages source?

I'm having trouble with my NuGet Installer build step.
We're using both official NuGet.org packages and our own packages hosted on the TeamCity NuGet server. If I leave Packages Sources blank, then packages from nuget.org are found, but as soon as I specify %teamcity.nuget.feed.server% as the package source, then packages from nuget.org are not found.
I tried setting Packages Sources to include both, but it still isn't working for official nuget.org packages.
https://nuget.org/api/v2/
%teamcity.nuget.feed.server%
Is that not the right URL for the nuget.org package source? How do I tell it to use both sources?
I asked this on the JetBrains Developer discussion board, but haven't gotten any responses.
Had same problem, funny enough my Nuget sources were specified as
https://www.nuget.org/api/v2/
http://nugetserver/nuget
Adding a forward slash on the second url to make it http://mynugetserver/nuget/ fixed the problem.
Took me a while to figure out. Now my Nuget-installer build step is running fine.
Apparently the NuGet Installer build step is not even needed. I edited the .nuget/NuGet.targets file to include both paths and removed the NuGet Installer build step and it works now.
When originally setting up TeamCity for this solution, it didn't work without the NuGet Installer step, so I don't know what else I've done differently to make this work, but maybe the NuGet.targets file was the key all along.
The comment on this blog post pointed me in the right direction.
You can modify the NuGet.Config in AppData local folder for the user that TeamCity runs under and not modify each project's .targets file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<config>
<!--<add key="repositoryPath" value="J:\TeamCity7\buildAgent\work\my_shared_packages_dir" />-->
</config>
<packageRestore>
<add key="enabled" value="True" />
</packageRestore>
<packageSources>
<add key="NuGet official package source" value="https://nuget.org/api/v2/" />
<add key="MMG TeamCity Nuget Server" value="http://myteamcityserver/guestAuth/app/nuget/v1/FeedService.svc" />
</packageSources>
<activePackageSource>
<add key="All" value="(Aggregate source)" />
</activePackageSource>
</configuration>
The NuGet.exe inside of .nuget folder in each project will respect the configs set here first, then apply any "overrides" done at the .targets file.
Same problem here. I am using TeamCity v10, Nuget step is required (no .targets file in my solution). However, I used another approach to add the "extra" package source:
c:\BuildAgent\tools\NuGet.CommandLine.2.7.0\tools\Nuget.exe sources Add -Name TeamCity-feed -Source http://myteamcityserver/guestAuth/app/nuget/v1/FeedService.svc/
After that, I added a Nuget installer step and did not specify anything in the package source box in TeamCity, now both packages from public feed nuget.org and my internal feed could be restored without problems.

Resources