NuGet.Server 返回 404 错误

标签 nuget nuget-server

我已关注 instructions设置和托管我自己的 NuGet 提要。我在 上运行 Web 应用程序Windows 2012 (IIS 8.5) 盒子。

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

上面写着“您正在运行 NuGet.Server v2.8.60318.667”
和“单击此处查看您的包裹”。

当我单击“此处”链接时,我收到“404 - 未找到文件或目录”。错误。

  • 我可以成功运行 nuget.exe push 命令来放置包
    Nuget 服务器;但是我在尝试运行时收到 404 错误
    nugget.exe 列表命令。
  • 我已经重新启动了 IIS 和服务器
  • 我从头开始重建了 NuGet.Server Web 应用程序。
  • 我曾尝试在 Windows 7 机器上托管 NuGet.Server,但没有
    成功。
  • Web.Config 有以下条目
    <modules runAllManagedModulesForAllRequests="true">
    
  • web.config 还有一个条目将 .nupkg 扩展名注册为 mimeType="application/zip"

  • 似乎 url 路由不起作用,但我似乎无法确定我做错了什么。有些东西阻止了 odata 提要工作。

    我知道 NuGet 服务器有很棒的 3rd 方实现,但我真的很想让免费的服务器运行起来,而且看起来应该很容易。任何想法或故障排除提示将不胜感激。

    最佳答案

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

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

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

  • 为了完成起见,我在下面包含了这些文件的转换后内容。

    默认.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
    

    关于NuGet.Server 返回 404 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30539179/

    相关文章:

    c# - 如何用本地构建临时替换 NuGet 引用

    visual-studio - 如何确保 nuget 程序集是按包添加的,而不仅仅是对 DLL 文件的引用?

    tfs - 如何在 nuget 包版本中添加 <release note> 节点?

    nuget - 如何获取离线安装的所有 nuget 依赖项

    c# - 将 Roslyn 与 Nuget 结合使用时避免大量的包和二进制文件

    c++ - Visual Studio 2017 上的 NuGet 包 "opencvdefault"链接错误

    powershell - 如何从 PowerShell 脚本引用 NuGet 包文件?

    NuGet 私有(private)提要未更新 DownloadCount

    version-control - 将 NuGet 用于 TFS 中的内部和外部依赖项

    .NET 标准程序集 : create nuget packages that can be used by . NET Core 和由本地 Nuget.Server 托管的完整 .NET