Search code examples
nugetnuget-server

NuGet.Server returns 404 error


I have followed the instructions to setup and host my own NuGet feed. I am running the web application on a Windows 2012 (IIS 8.5) box.

I build and run the solution and get the default.aspx page...

Which says "You are running NuGet.Server v2.8.60318.667" and "Click here to view your packages".

When I click on the "here" link I get a "404 - File or directory not found." error.

  • I can successfully run a nuget.exe push command to put packages on the Nuget server; however I get a 404 error when attempting to run nugget.exe list command.
  • I have restarted IIS and the server
  • I have rebuilt the NuGet.Server web application from scratch.
  • I have tried hosting the NuGet.Server on a Windows 7 box with no success.
  • The Web.Config has the following entry

    <modules runAllManagedModulesForAllRequests="true">
    
  • The web.config also has an entry to register the .nupkg extension as mimeType="application/zip"

It seems like the url routing is not working, but I can't seem to pin down what I am doing wrong. Something is preventing the odata feed from working.

I know there are great 3rd party implementations of NuGet server, but I would really like to just get the free one working and it seems like it should be so easy. Any thoughts or troubleshooting tips would be appreciated.


Solution

  • This answer expands the comment left on AndrewD's answer.

    Like him, I started out with a VB project and I ended up in the same camp as OP. What worked for me however was converting all C# code into VB, within these two files.

    1. Default.aspx
    2. NuGetODataConfig.cs (replaced this one with a new file: NuGetODataConfig.vb)

    For the sake of completion, I'm including the post-converted contents of these files below.


    Default.aspx

    <%@ Page Language="VB" %>
    <%@ Import Namespace="NuGet.Server" %>
    <%@ Import Namespace="NuGet.Server.App_Start" %>
    <%@ Import Namespace="NuGet.Server.Infrastructure" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>NuGet Private Repository</title>
        <style>
            body { font-family: Calibri; }
        </style>
    </head>
    <body>
        <div>
            <h2>You are running NuGet.Server v<%= Gettype(NuGetODataConfig).Assembly.GetName().Version %></h2>
            <p>
                Click <a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/Packages") %>">here</a> to view your packages.
            </p>
            <fieldset style="width:800px">
                <legend><strong>Repository URLs</strong></legend>
                In the package manager settings, add the following URL to the list of 
                Package Sources:
                <blockquote>
                    <strong><%= Helpers.GetRepositoryUrl(Request.Url, Request.ApplicationPath) %></strong>
                </blockquote>
                <% if string.IsNullOrEmpty(ConfigurationManager.AppSettings("apiKey")) Then %>
                To enable pushing packages to this feed using the <a href="https://www.nuget.org/downloads">NuGet command line tool</a> (nuget.exe), set the <code>apiKey</code> appSetting in web.config.
                <% else  %>
                Use the command below to push packages to this feed using the <a href="https://www.nuget.org/downloads">NuGet command line tool</a> (nuget.exe).
                <blockquote>
                    <strong>nuget.exe push {package file} {apikey} -Source <%= Helpers.GetPushUrl(Request.Url, Request.ApplicationPath) %></strong>
                </blockquote>
                <% end if %>
            </fieldset>
    
            <% if Request.IsLocal Then  %>
            <fieldset style="width:800px">
                <legend><strong>Adding packages</strong></legend>
    
                To add packages to the feed put package files (.nupkg files) in the folder
                <code><% = PackageUtility.PackagePhysicalPath %></code><br/><br/>
    
                Click <a href="<%= VirtualPathUtility.ToAbsolute("~/nuget/clear-cache") %>">here</a> to clear the package cache.
            </fieldset>
            <% End If %>
        </div>
    </body>
    </html>
    

    NuGetODataConfig.vb

    Imports System.Net.Http
    Imports System.Web.Http
    Imports System.Web.Http.ExceptionHandling
    Imports System.Web.Http.Routing
    Imports NuGet.Server
    Imports NuGet.Server.Infrastructure
    Imports NuGet.Server.V2
    
    <Assembly: WebActivatorEx.PreApplicationStartMethod(GetType(MGINuGet.App_Start.NuGetODataConfig), "Start")>
    
    Namespace MGINuGet.App_Start
        Public Module NuGetODataConfig
            Public Sub Start()
                ServiceResolver.SetServiceResolver(New DefaultServiceResolver())
    
                Dim config As HttpConfiguration = GlobalConfiguration.Configuration
    
                NuGetV2WebApiEnabler.UseNuGetV2WebApiFeed(config, "NuGetDefault", "nuget", "PackagesOData")
    
                config.Services.Replace(GetType(IExceptionLogger), New TraceExceptionLogger())
    
                Trace.Listeners.Add(New TextWriterTraceListener(System.Web.Hosting.HostingEnvironment.MapPath("~/NuGet.Server.log")))
                Trace.AutoFlush = True
    
                config.Routes.MapHttpRoute(name:="NuGetDefault_ClearCache",
                                           routeTemplate:="nuget/clear-cache",
                                           defaults:=New With {Key .controller = "PackagesOData", Key .action = "ClearCache"},
                                           constraints:=New With {Key .httpMethod = New HttpMethodConstraint(HttpMethod.Get)})
            End Sub
        End Module
    End Namespace