TeamCity NuGet Feed: Configure Feed URL - nuget

I'm attempting to set up my TeamCity instance as a private NuGet package feed. I have successfully configured the feed and set up a build that publishes artifacts.
However, I'm running into a problem when attempting to install a package in my source code from the TeamCity feed:
By going to the "NuGet Feed" page in TeamCity, I can see that the feed URL is
http://localhost:8080/httpAuth/app/nuget/v1/FeedService.svc/.
I have set my local Visual Studio (running on my local machine, not the TeamCity server) as
http://[my-TC-server]/httpAuth/app/nuget/v1/FeedService.svc/, and I can view the package in the NuGet manager with the expected attributes.
However, when I try to install the package, it fails because the src attribute in the package configuration is still set to http://localhost:8080/httpAuth/app/nuget/v1/FeedService.svc/download/NuGet_[myPackage]/73:id/p[myPackage].nupkg (I can see this by viewing my TeamCity-hosted packages at http://[my-TC-server]/httpAuth/app/nuget/v1/FeedService.svc/Packages()), and the install fails because it is looking on my machine for the package file, and not on the TeamCity server. I assume the src attribute is set at pack time and grabbed from the TeamCity configuration somewhere.
If I navigate to to
http://[my-TC-server]/httpAuth/app/nuget/v1/FeedService.svc/download/NuGet_[myPackage]/73:id/p[myPackage].nupkg
in a browser, I can successfully download the package.
Is it possible to configure the feed URL in TeamCity to be http://[my-TC-server]/httpAuth/app/nuget/v1/FeedService.svc/ so that the src param will also use [my-TC-server] instead of localhost? I can't find an option in TC to do this, and I haven't found any documentation for dealing with this problem.
If it is not possible to configure the feed URL, what would a good solution be so that my local machine can download the package from my TeamCity server?

It was two things:
I needed to configure my TeamCity Server URL (Administration>General Settings)
I was running into this problem with my server's reverse proxy, and running this command on the server fixed the problem (the server was not preserving the Host header in requests)
After those two, everything's all good!

Related

Nuget Server issue post migration to Win 2016

I have migrated nuget repository from Win 2008 to Win 2016.
Alias to that server: http://xyz.mycompany.com/NugetFeed
Apart of windows, IIS is different as well, on the new server it is IIS 10.
After migration, nuget works pretty well, except one function. I can browse packages via web (http://xyz.mycompany.com/NugetFeed) or via Visual Studio etc. Visual Studio can see packages created manually.
The only problem is with the nuget push.
>nuget push FEDivaNET.dll*.nupkg -Source http://xyz.mycompany.com/NugetFeed/ D568CD48-1609-40C9-9A5D-7ADC808129E5
Pushing FEDivaNET.dll.3.41.73.nupkg to 'http://xyz.mycompany.com/NugetFeed/'...
PUT http://xyz.mycompany.com/NugetFeed/
NotFound http://xyz.mycompany.com/NugetFeed/ 128ms
Response status code does not indicate success: 404 (Not Found).
System.Net.Http.HttpRequestException: Response status code does not indicate success: 404 (Not Found).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at NuGet.Protocol.Core.Types.PackageUpdateResource.<>c.<PushPackageToServer>b__23_0(HttpResponseMessage response)
at NuGet.Protocol.HttpSource.<ProcessResponseAsync>d__181.MoveNext()
It is not a problem with the URL. When you try to modify URL then you will get different error
It is not a problem with permissions to D:\MyServer\NugetPackages on server, as I have set full permissions to that folder. I have also moved packages folder to different locations (ie. some other external network drive), but I am having same issue.
I tried compiling 2 different Nuget.Server versions: 2.14.0 and 3.1.2 ...Same exception.
Inside IIS, I am pretty sure I have set same settings as on the old server. Also I have INTEGRATED pipeline mode, so everything is good. I also tried setting authentication via technical users etc.
Not sure where is the issue, I think I checked every single setting. I tried with APIKEY, and without APIKEY. I modified every single setting in the Web.config, no luckā€¦..
The url on which push the nuget packet is something like
http://{server}/{feed}/api/v2/package
So in your command use:
nuget push FEDivaNET.dll*.nupkg -Source http://xyz.mycompany.com/NugetFeed/api/v2/package
Documentation : Publish a package
When you create website in IIS 10, then by default PUT verb is not allowed.
This can be set here:
IIS -> YOUR WebSite -> Request Filtering -> HTTP Verb tab: **Set PUT verb**
This has fixed an issue.

Hosting private nuget server issue

I have setup my own nuget feed and have hosted that on our dev server.
When I try to push my packages from my local machine to dev machine as below:
dotnet nuget push C:\MyProjects\Common.2.0.0.nupkg -k myapi -s https://mydev.com/AENuget/
I get the error as:
Response status code does not indicate success: 405 (Method Not Allowed).
Now I have read and tried many settings like adding
<remove name="WebDAV" /> <remove name="WebDAVModule" />
Giving permissions to my nuget packages folder, adding app pool account but still I am not able to resolve this issue.
Secondly instead of pushing if I just copy my nuget package file to the package folder being hosted in our dev server and then in visual studio I add the new server source I get the below error:
[Package Source] The V2 feed at 'http://mydev.com/AENuget/Search()?$filter=IsLatestVersion&searchTerm=''&targetFramework=''&includePrerelease=false&$skip=0&$top=26&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'.
So looks like neither the push from nuget nor the copy is working. Looks like some permission issue which I am not able to resolve.
Would appreciate if someone can provide any inputs to this.
FYI: This works fine if I host this on my local machine.
The problems you are having seem to indicate you are having issues with the NuGet.Server and the system itself. These can be problems with the firewall, hosting configuration (IIS), or a wide variety of problems.
If you are on a very small team, you might just create a shared folder on a network server (with read/write access for the team). You can add the package source to Visual Studio by following this article. The source will be the UNC path to the directory (e.g. \\servername\path\to\nuget\folder).
NuGet.Server is a package provided by Microsoft and NuGet. This is used widely so I do not believe you have a problem with the package. If you encounter a specific problem, we may be able to help.

Installing a NuGet package from command-line from a private feed

Is it possible to fetch a NuGet package from a private feed (i.e., requiring login/password) within a script?
I have a NuGet package with a single JSON file. It's hosted on a private TeamCity feed. I want to use that JSON in a script, so here's what I'm trying to do:
nuget sources add -Name tc -Source https://xxxxxxxxx/ -Username username -Password password
nuget install xxxxxxxx -source tc
nuget sources remove -Name tc
Which results into Unable to find version '1.0.7' of package 'xxxxxxx'. Which is strange, for it's obviously able to reach the feed since it see the version of the package, but can't download the package.
I also tried to install the package into a dummy .sln and run nuget restore xxxxx.sln. NuGet is then asks me to provide credentials, two times:
Please provide credentials for: https://xxxxxxxx/httpAuth/app/nuget/v1/xxxxx.svc/
Please provide credentials for: https://xxxxxxxx/httpAuth/repository/download/xxxxx/1148145:id/xxxxxxxx.1.0.7.nupkg
Creating a NuGet.config with a feed & credentials declaration also results into the same Unable to find error.
It works OK when I'm installing/restoring the package from VS.
These two questions seems related:
NuGet Package Restore Unable to prompt for credentials with custom feed
https://stackoverflow.com/questions/24682237/nuget-command-line-authentication-not-working
It looks like it's a problem with the TC feed. I didn't think that was the case because I can use the feed from VS Package Manager, the problem is only with command-line NuGet.
I turned on -Verbosity detailed (thanks danliu) and here's what I saw:
GET https://xxxxxx/httpAuth/app/nuget/v1/FeedService.svc/Packages(Id='xxxxxx',Version='1.0.7')
GET https://xxxxxx/httpAuth/app/nuget/v1/FeedService.svc/Packages(Id='xxxxxx',Version='1.0.7.0')
System.InvalidOperationException: Unable to find version '1.0.7' of package 'xxxxxx'.
The request GET https://xxxxxx/httpAuth/app/nuget/v1/FeedService.svc/Packages(Id='xxxxxx',Version='1.0.7') returns 404, I think it's related to server configuration problem which is mentioned in TeamCity NuGet feed settings:
NuGet Feed must contain server URL inside. Current TeamCity server configuration does not let TeamCity server to get original request URL from HTTP request. It looks like TeamCity server is wrongly configured with reverse proxy. Make sure reverse proxy and TeamCity server is configured to let TeamCity server know request real request URL.
I tried to host the package on MyGet and install it from there. It worked out.

Create a NuGet package while offline

I want to create a NuGet package from a machine that is on the office intranet, but blocks all connections to the internet.
Both NuGetPackageExplorer.application and NuGet.exe will show the exception that "No connection could be made because the target machine actively refused it".
Installing packages works fine as we have a local network folder with the .nupkg packages we use.
Is there a tool I can use to create a NuGet package on that machine?
Update:
I created a issue on codeplex for this: https://nuget.codeplex.com/workitem/3196
What I ended up doing is downloading the source code from CodePlex, going into the CommandLine project, deleting UpdateCommand.cs, and rebuilding the project. I then grabbing the exe which I renamed NuGetOffline.exe and put it along with NuGet.Core.dll to somewhere in the Path.
Update
The download page for NuGet does not have the current version of NuGet.exe. As of writing this, none of the three downloads on the page work offline and the Other Downloads have several version of Nuget.Tools, but not the current version of NuGet.exe. Go here instead for nuget.exe. Use that instead of that custom build.
The Package Explorer link on the download page is just the ClickOnce installer which does work offline. You need to find the local executable here.
I haven't been able to get "Enable NuGet Package Restore" to work on the intranet. This closed work item describes the problem. The last comment says that "2.0 should no longer run into this issue", but I am using NuGet Package Manager 2.2.400116.9051.

NuGet is returning 503 Server Unavailable

Is there a way to load a package from an alternative server when Visual Studio Package Manager (NuGet) is responding with a "The remote server returned an error: (503) Server Unavailable" message?
This is an obscure condition that will likely only occur on an "enterprisy" network environment. If these conditions apply you:
you are required to access the Internet via an HTTP proxy server
the HTTP proxy server requires a valid user ID & password (or AD authentication) to allow requests to proceed
you've been messing with cool developer tools that were ported to Windows from a Linux/Unix environment
the new cool tool(s) work after adding the HTTP_PROXY (or possibly HTTPS_PROXY or both) environment variable(s)
you can access the NuGet servers from a browser without getting a 503 error
Then it's likely you broke NuGet by inadvertently invoking this configuration feature. I'm not sure exactly how the environment variable breaks NuGet but I suspect NuGet is detecting & using the http_proxy URL but sending an empty user ID & password which causes the HTTP proxy to reject the request.
Fix: remove the environment variable(s) you added and see if the cool tool can be configured to use an HTTP proxy without them.
Update: Ran into a version of this issue with the NuGet config file referenced in the "this configuration feature" link above. Open this file:
%appdata%\nuget\nuget.config
in your favorite editor. If it contains elements with http_proxy or https_proxy then removing these elements may fix the issue too.
PS: Hopefully I'll get an up vote from Colonel Panic :-)
If you have used the package in the past it is probably in your cache. You can add the local cache as an available package source by going into the Library Package Manager Settings under the Tools menu in Visual Studio. For Visual Studio 2012, choose Tools, Library Package Manager, Package Manager Settings, and then click on Package Sources.
In the Available package sources section, type a name like "Cache" and then in for the source, browse to %LocalAppData%\NuGet\Cache. You may need to use Windows Explorer to translate %LocalAppData%\NuGet\Cache into the full path (usually C:\Users\YourAccountName\AppData\Local\NuGet\Cache).
Once you have the Cache as an available source, you can now use the Package Manager Console (found under the View menu under Other Windows or also under the Tools menu under Library Package Manager).
From the Console (which is a PowerShell window with commandlets for NuGet) you can type "get-help NuGet" to see available commands.
Then using Get-Package, you can get a list of Package ID's. Make sure the "Package source" is set to "Cache" (or whatever you called it) and the Default project is set to the project you need manipulate, both of these are dropdowns located at the top of the Page Manager Console. You can also use the Get-Project to verify you are working against the correct project in your solution.
Finally, you can type Install-Package and when prompted enter the Package ID from the output of the Get-Package commandlet.
i had also this problem, it was becouse of my network.
if you have any blocking on your Internet, (like in companies internet or etc..)
you may not allowed to download the nuget package.
try to download the package in another network, maybe it can help you!
Talbott's answer did not work for me, as my cache was empty. However, if you have used the package in another solution, you can copy the items you want from the "packages" folder in the other solution to a packages folder in your target solution.
If you have no packages installed in the target solution, you may need to add the following to a repositories.xml file in the packages folder:
<?xml version="1.0" encoding="utf-8"?>
<repositories>
</repositories>
After doing that, the packages appeared to be installed in my solution and I was able to add them to projects.
Additional Note: I had to use the "Manage NuGet Packages for Solution" option at the solution level to add the package to individual projects. Using Install-Package from the console still returns a 503 even though the packages is already installed in the solution.
You can also get this error if you are using a VPN client (e.g. Cisco AnyConnect) and you have recently renewed your VPN certificate. The issue can occur after you have updated your certificate, but before you have rebooted. A reboot resolves the issue.
It is a pretty old question, but I have just encountered the same problem. In my case it occurred because I had more than one nuget package source configured in the Visual Studio Package Manager. In my company we use NuGet to get mainstream packages and MyGet for our own stuff.
When I attempted to pull a pretty big package it failed with a 503 code and the error link looked pretty odd, it had MyGet in it istead of NuGet. Turns out Visual Studio package manager tried to pull it from another source despite having NuGet chosen as a current source. Disabling other sources and then proceeding with a download fixed it.
Hopefully it will help somebody who stumbled upon this thread just like I did.
Another possible reason for recieving 503: If you're using Azure DevOps feed, then NuGet packages are limited to 500 MB.