首页 文章

NuGet.Server返回404错误

提问于
浏览
13

我按照instructions来设置和托管我自己的NuGet提要 . 我在 Windows 2012 (IIS 8.5) 框上运行Web应用程序 .

我构建并运行解决方案并获取default.aspx页面...

其中显示“您正在运行NuGet.Server v2.8.60318.667”和“单击此处查看您的包” .

当我点击“这里”链接时,我得到一个“404 - 文件或目录未找到” . 错误 .

  • 我可以成功运行nuget.exe push命令将包放在Nuget服务器上;但是在尝试运行nugget.exe list命令时出现404错误 .

  • 我已重启IIS和服务器

  • 我从头开始重建了NuGet.Server Web应用程序 .

  • 我试过在Windows 7机箱上托管NuGet.Server但没有成功 .

  • Web.Config具有以下条目

<modules runAllManagedModulesForAllRequests="true">
  • web.config还有一个用于将.nupkg扩展名注册为mimeType =“application / zip”的条目

看起来网址路由不起作用,但我似乎无法确定我做错了什么 . 有些事情阻止了odata饲料的运转 .

我知道NuGet服务器有很好的第三方实现,但我真的想让免费的一个工作,看起来应该这么简单 . 任何想法或疑难解答提示将不胜感激 .

10 回答

  • 1

    如果你将项目命名为Nuget.Server,因为你生成的dll将是Nuget.Server.dll,它将无法工作,因为Nuget.Server.dll是服务器的实际dll . 将您的程序集名称重命名为其他名称 .

  • 0

    如果您创建一个新的空VB项目,您还将获得404(在包中并使用NuGet Manager进行浏览) .

    您似乎必须将项目创建为 C# ,它的工作方式与宣传的一样!

    然而源代码看起来相同:(

  • 0

    我找到的任何一个帖子都没有提到一个答案 . 如果您将项目命名为Nuget.Server,即使发布将在IIS中工作,ninject也将无法设置包列表路由,因为它将尝试加载错误的DLL并输出错误 .

    以下是其他一些可能的答案:

    Possible Answers 1

    Possible Answers 2

  • 1

    %APPDATA%\ NuGet或$(SolutionDir).nuget中的NuGet.config文件可能指的是意外的“活动源”URL . 例如,TFS构建代理程序安装带来的nuget.exe可能只知道NuGet v2协议,而URL指的是v3协议 . 或者NuGet.config中可能缺少自定义NuGet服务器URL .

  • 3

    我有类似的问题,我找到了解决方案!我创建了一个私有nuget服务器,按照说明创建一个空的ASP.NET项目(我在VS2015上),然后安装nuget.server(目前是v2.11.3.0) . 我能够运行并看到网页,除了我无法使用“nuget.exe push”上传包 . 我得到了可怕的404未找到错误 .

    我最终克隆了github上的nuget.server源代码并直接运行了哪个工作正常!?我发现我的 web.config 不正确 . 对我来说,关键是

    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,PUT,DEBUG" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0"/>
    

    在里面

    <system.webServer>/<handlers>
    

    部分 .

    我建议有问题的人应该去github并比较web.config文件 .

    BTW: nuget.server 安装应该替换你的 web.config . 这对我来说可能没有用 .

  • 1

    我注意到当你尝试上传相当大的nuget包时,你会收到404错误 . 我提升了 maxAllowedContentLength 并且它有所帮助 .

    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="31457280"/>
        </requestFiltering>
      </security>
    </system.webServer>
    
  • 3

    FWIW,我错误地试图从http://[server]/nuget/Packages获取包并得到了同样的错误 . 从源URL末尾删除/ Packages是答案,因此http://[server]/nuget是正确的URL .

  • 1

    我今天遇到这个问题 . 实际上我需要做的是在Global.asax中:

    void Application_Start(object sender, EventArgs e) 
    {
        NuGetRoutes.Start();
    }
    
  • 0

    我有一个干净的 Visual Studio 2017 Web项目有这个问题 .

    Visual Studio 2015 重新创建并以.NET 4.6.1为目标进行重新排序

  • 1

    这个答案扩大了AndrewD's answer上留下的评论 .

    像他一样,我从一个VB项目开始,我最终和OP一样在同一个阵营 . 然而,对我来说有用的是在这两个文件中将所有C#代码转换为VB .

    • Default.aspx

    • NuGetODataConfig.cs(用新文件替换了这个:NuGetODataConfig.vb)

    为了完成,我将在下面包含这些文件的转换后内容 .


    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>

    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
    

相关问题