Nuget Packages are not found in nexus repo - visual-studio

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.

Related

How to add new packages when using an Azure Artifcat as package source

Due to our obfuscasting library(Babel4), we had to create a Azure artifact to host their nuget package.
It works fine, but if we try to add a package that has never been referenced in our .Net Core project(in visual studio), we cannot find it.
I was able to manually install it through the command line:
Install-Package Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson
but then on another computer if I try to restore the references, I get this error:
XXX.YYY: [NU1101] Unable to find package
Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson. No packages exist with this id in source(s): Babel3
(Babel3 is our artifact name).
But Azure Artifacts has Nuget(and other) configured as upstream sources:
On Azure Artifact, if I try to look for a package that I don't have installed, it doesn't find it(and I'm owner of the artifact):
What should I do? Configure another package source in Visual Studio? Something on azure?
Thank you very much
EDIT
Here is is my nuget.config if it helps:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<add key="Babel3" value="https://pkgs.dev.azure.com/XXXXX/_packaging/Babel3/nuget/v3/index.json" />
</packageSources>
<config>
<add key="repositoryPath" value="packages\" />
<add key="globalPackagesFolder" value="packages\" />
</config>
</configuration>
Please go to Feed settings for Babel3 -> Check if you have added "Project Collection Build Service(org)" and "project build service(org)" as collaborator, contributor, or owner role. As per the doc, if you don't have enough permission on feed, the pipeline cannot fetch package from upstream.
I can fetch the nuget package from upstream to local feed.
BTW, please make sure the project settings -> pipelines -> settings -> Job authroized scope is not limited if the feed from another project.
Edit:
Since you restore from local machine and "nuget gallery" is public resource. Please try to add it directly in nuget.config.

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.

Self-hosted Azure Devops build cant resolve packages

I have a Azure DevOps build pipeline that runs as expected on a hosted vs2017 agent, but fails on a self-hosted agent.
The error I get in the Visual Studio build step is:
C:\WINDOWS\TEMP\.NETStandard,Version=v2.0.AssemblyAttributes.cs(4,20): Error CS0400: The type or namespace name 'System' could not be found in the global namespace (are you missing an assembly reference?)
The two agents seems to run the same version of msbuild.
From the diagnostic output from msbuild I can see that the output from the ResolvePackageDependencies task contains a lot of packages where the ResolvedPath is empty, for instance:
runtime.native.System/4.3.0
Name=runtime.native.System
Path=runtime.native.system/4.3.0
ResolvedPath=
Type=package
Version=4.3.0
But the NuGet restore step seems to complete without problems.
Any suggestions for what I am missing?
I believe I had a similar issue. I ended up having to install the latest Nuget and then run Nuget on the solution including a NuGet.config file.
Add a nuget.config to your solution so it is part of your repo/pull. Mine is in the same directory as the solution file. Example below
Add a task "NuGet Tool Installer" - I install NuGet 4.4.1, just put 4.4.1 in the Version to install input.
Add a task "NuGet Installer" - Different from above. Version 0.* - I have not tried the other versions.
Set the Path to the solution. IE. $(Build.Repository.LocalPath)/Source/Sample.sln
Add the path to the Nuget config file. Example $(Build.Repository.LocalPath)/Source/nuget.config
Nuget.config contains how to get the packages. Add other locations if you get packages from other sources like a local folder or something.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<!--
Used to specify the default Sources for list, install and update.
See: nuget.exe help list
See: nuget.exe help install
See: nuget.exe help update
-->
<packageSources>
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
</packageSources>
<packageRestore>
<!-- Allow NuGet to download missing packages -->
<add key="enabled" value="True" />
<!-- Automatically check for missing packages during build in Visual Studio -->
<add key="automatic" value="True" />
</packageRestore>
Your build task should run fine now and find all the packages.
Self-hosted Azure Devops build cant resolve packages
According to the error message, it seem nuget not restore the reference from SDK.
To resolve this issue, we need update our nuget.exe version to 4.0 and above.
In the NuGet tool installer we could specify the nuget.exe version:
As you comment above, it seems you have already use nuget installer, in this case, you can try to update Visual Studio to 15.3 and above on the build server. Because VS only adds proper support for .NET Core 2.0 SDK in version 15.3.
Finally, if your project/solution is .net core/standard you can use dotnet restore and then run dotnet build to compile your app.
Hope this helps.

Nuget package source setup

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:

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