From Nuget.Server to NugetGallery
Well, we started running into an issue with Nuget.Server and it was time to migrate to NugetGallery. Mainly, it wouldn't clean itself up (after a few days, there were 10's of gigs of temp files in c:\windows\temp\nuget
), and now that we have a couple thousand packages it started really slowing down. It was just time. So here goes what I did to make this work.
Initial Steps:
- Clone NugetGallery from github
- Configure NugetGallery settings (database, etc)
- Modify the
web.config
in the NugetGallery project- Change
appSettings/Gallery.SiteRoot
to whatever it should be, I could only see this in the email verification - If you want to actually send the emails, set
appSettings/Gallery.SmptUri
tosmtp://<user:pass>@server:<port>
. If you use just a server name (like a lot of smtp servers) just usesmtp://server
. If you don't set it, they will be stored in theApp_Data
folder. - Empty the
appSettings/Gallery.ServiceDiscoverUri
, by default it is set to "n", you will receive an exception stating something about relative uri's are not valid if you dont either empty this or set it to a valid url. - Update
appSettings/Gallery.Brand
to say something likeCompany - Nuget
. This makes it easy to see that it's your local nuget as it updates the<title></title>
tag in the pages. - Set the
appSettings/Gallery.GalleryOwner
to be the correctfrom
email address in the format ofemail@domain.tld <Display Name>
. The< >
must be the escaped<>
in order for it to work. - Update the database connection string.
connectionStrings/Gallery.SqlServer
- if you want sql express you don''t want to change it. But I''m not, so I modified it to point to a local server. Be sure to create the database you want to use before hand and set the Initial Catalog. - That''s it.
- Change
Problem areas:
-
Issue: Database Generation and errors saying it couldn't find EntityFramework 5.0.0 library as well as saying method not found or some such non-sense.
- I have VS2015 installed on my dev system, I don't want VS2013 and I don't want to install it
- The Fix (install EntityFramework5 into the GAC):
- Open VS2015, don't open any projects.
- Open the package manager console
- Open the NugetGallery solution.
- Build the solution (this will download all packages)
- Open up a developer prompt
- "cd" into the Solution folder
cd into Packages\EntityFramework5.0.0\lib\net45
- Run
gacutil /i EntityFramework.dll
- Back in the package manager, in VS2015,
- Select the nugetgaller as the "project"
- run
update-database
-
Issue: Server only has .net 4.5.1 (annoying, but I wasn't allowed to update it to 4.5.2)
- The projects downgrade nicely to 4.5.2, except for one spot where it actually uses a method introduced in 4.5.2.
- You will also need to go through the
packages.config
files in each of the projects and replace the 452 with 451
src/NuGetGallery/Controllers/ApiController.cs
needs to have the line where it callsQueueBackgroundWorkItem
modified. I commented that line and just called thePostDownloadStatistics
directly, passing anew CancellationToken()
. Problem solved- HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => PostDownloadStatistics(id, version, userHostAddress, userAgent, operation, dependentPackage, projectGuids, cancella + //HostingEnvironment.QueueBackgroundWorkItem(cancellationToken => PostDownloadStatistics(id, version, userHostAddress, userAgent, operation, dependentPackage, projectGuids, cancel + await PostDownloadStatistics(id, version, userHostAddress, userAgent, operation, dependentPackage, projectGuids, new CancellationToken());
-
Issue: Lucene indexes needed to be refreshed on every package upload at the time of upload. Since we don't upload very often, the performance impact was minimal.
- Add
IndexingService.UpdateIndex(true)
; to the methods in insrc/NuGetGallery/Controllers/ApiController.cs
that update and upload the packages. This code goes right below theIndexingService.UpdatePackage(package)
lines.
- Add
-
Issue: Not an admin user
- When registering the first user, you're not an admin user. The fix was to add the user/role to the
UserRoles
table. By default you will probably want to add aUserKey=1
andRoleKey=1
to the table. You get the keys from the Users and Roles tables. - In order to make additional users admin users, it looked like it was a manual process. Though this was possible through the admin interface when you logged in as an admin.
- When registering the first user, you're not an admin user. The fix was to add the user/role to the
-
Issue: Development message at the top of the page. "This is a development environment. No data will be preserved." and other customization
- The development message is in:
src\NugetGallery\App_Data\Files\Content\Alert.md
- Other page content is located in the other files in that folder.
- The development message is in: