NuGet’s great and there are plenty of resources to help get your team setup with private feeds (MyGet, Inedo's ProGet, JFrog's Artifactory, Sonatype's Nexus), but sometimes there are needs to host your own feed internally.
It’s not too hard to do, but there are a few hoops that you need to jump through in order to get it all setup:
- NuGet already provides a great guide for downloading the Gallery code and getting it running on your local machine.
- They also have a guide for altering the Gallery code (LocalGuide) to prepare it to run on a local IIS instance.
- But, there are a few details that you might want to change to customize the Gallery for your organization/needs:
- At the end of the LocalGuide it mentions “you can register a user and make it an Admin by adding a record to the UserRoles table”. Here’s the script:
select * from [dbo].[Users] -- find your id insert into [dbo].[Roles] (name) values ('Admins') insert into [dbo].[UserRoles] (UserKey, RoleKey) values (<your id>, 1)
- Remove Alert.md – This feeds the yellow bar that appears at the top of the screen and states “This is a development environment. No data will be preserved.”
- It’s under FrontEnd/NuGetGallery/App_Data/Files/Content/Alert.md
- I think it’s a good idea to remember that file. It’s a really nice implementation to be able to set an alert without disrupting the service.
- Update Web.config – These will kinda be obvious
- Gallery.Environment should be empty
- Gallery.SiteRoot
- Gallery.SmtpUri
- Gallery.Brand
- Gallery.GalleryOwner
- Remove <rewrite> rules (from LocalGuide)
- Update the Title Icon/Name – This is defined by CSS
- FrontEnd/NuGetGallery/Content – Both Layout.css and Site.css (it’s just a good idea to keep them insync)
- If you have the time to make a new image, that would be best.
- If you don’t have time, then
- comment out
- background
- text-indent
- add
- font-weight: bold
- color: white
- font-size: 1.2 em
- text-decoration: none
- The Web.Config setting of Gallery.Brand text will be displayed
- comment out
- Add Gallery URL
- FrontEnd/NuGetGallery/Views/Pages/Home.cshtml
- Add some text before @ViewBag.Content like: Visual Studio URL: http://nuget.xyz.com/api/v2/
- Have Lucene Search Index update on each package upload
- FrontEnd/NuGetGallery/Controllers/ApiController – PublishPacakge function – By default the line IndexingService.UpdatePackage(package) is supposed to update the search index. But, sometimes it doesn’t.
- Replace that line with: IndexingService.UpdateIndex(forceRefresh: true)
- At the end of the LocalGuide it mentions “you can register a user and make it an Admin by adding a record to the UserRoles table”. Here’s the script:
I’m sure the first thing you’ll want to do once you have the website up and running is play around with some test packages. Here is a script to help cleanup the database once you’re done testing. (Also, delete any .nupkg files under <website>/App_Data/Files/packages/)
declare @trunc bit = 0 if(@trunc = 1) begin truncate table [dbo].[GallerySettings] truncate table [dbo].[PackageAuthors] truncate table [dbo].[PackageDependencies] truncate table [dbo].[PackageRegistrationOwners] delete from [dbo].[PackageStatistics] where [key] = 1 delete from dbo.Packages where [key] = 1 delete from [dbo].[PackageRegistrations] where [key] = 2 /*delete from [dbo].[UserRoles] where [Userkey] = 1 delete from [dbo].[Users] where [key] = 1*/ end /****** Script for SelectTopNRows command from SSMS ******/ select * from [dbo].[GallerySettings] select * from [dbo].[PackageAuthors] select * from [dbo].[PackageDependencies] select * from [dbo].[PackageRegistrationOwners] select * from [dbo].[PackageRegistrations] select * from dbo.Packages select * from [dbo].[PackageStatistics] /*select * from [dbo].[Roles] select * from [dbo].[UserRoles] select * from [dbo].[Users]*/