Nuget返回了一个意外的状态代码'404 Not Found' - 本地驱动器上的包

时间:2018-01-16 05:27:28

标签: c# .net visual-studio nuget nuget-package

尝试从dll生成Nuget包。我们的一个项目是生成ConfigurationCore.dll和项目程序集的引用,如下所示

  • Microsoft.CSharp
  • Newtonsoft.Json
  • Mak.Enums(本地Nuget服务器上提供自定义Nuget包)
  • Mak.Operations(本地Nuget服务器上提供自定义Nuget包)
  • PresentationCore,PresentationFramework,PresentationFramework.Aero
  • System,System.Core,System.Data,System.Data.DataSetExtensions
  • System.Drawing,System.IO.Compression,System.IO.Compression.FileSystem
  • System.Net.Http,System.Runtime.Serialization,System.Web
  • System.Xaml,System.Xml,System.Xml.Linq,WindowsBase

使用下面的ConfigurationCore.nuspec生成Nuget包

<?xml version="1.0"?>
<package >
<metadata>
<id>ConfigurationCore</id>
<version>1.2.0</version>
<title>Configuration Core</title>
<authors>MAKK</authors>
<owners>IT Department</owners>
<requireLicenseAcceptance>false</requireLicenseAcceptance>
<description>ConfigurationCore contains core funcationality of Software</description>
<releaseNotes></releaseNotes>
<copyright>Copyright 2018</copyright>

<dependencies>
  <dependency id="Newtonsoft.Json" version="10.0.3" />
</dependencies>
</metadata>
<files>
<file src="C:\Users\makk\source\repos\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
</files>
</package>

尝试针对项目'NugetTest'收集程序包'ConfigurationCore.1.2.0'的依赖关系信息,目标是'.NETFramework,Version = v4.6.1' 收集依赖信息需要1.09秒 尝试使用DependencyBehavior'Lowest'解决包'ConfigurationCore.1.2.0'的依赖关系 解析依赖性信息需要0毫秒 解决安装包'ConfigurationCore.1.2.0'的操作 解决了安装包'ConfigurationCore.1.2.0'的操作 'http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&amp; semVerLevel = 2.0.0'的V2 Feed返回了意外状态代码'404 Not Found'。 经过的时间:00:00:02.1513344 ==========完成==========

注意:Nuget包源是在本地硬盘上...请建议解决问题。

5 个答案:

答案 0 :(得分:1)

  

Nuget返回了意外的状态代码&#39; 404 Not Found&#39; - 本地驱动器包装

  1. 确保src="..."中的路径正确无误。

    也许路径应该是:

    ...\ConfigurationCore\ConfigurationCore\... 而不是 ...\ConfigurationCore\...

    简而言之,请确保您可以在该网址上找到dll文件。

    注意:通常,我们建议在url中使用相对路径,例如:

    <file src="bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />

  2. 更新nuget.exe的版本。

    nuget.exe 3.4.x上有an issue,所以请下载nuget.exe 3.5及以上版本。

  3. 有关详细信息,请参阅Create nuget package from dlls

    <强>更新 请按照以下步骤创建nuget包:

    1. 下载nuget.exe,并在您的本地设置,例如D:\NuGetLocalFolder

    2. 使用项目名称&#34; ConfigurationCore&#34;创建一个新项目。

    3. 打开cmd并切换到之前存储nuget.exe的路径。

    4. 使用命令行:

      nuget spec "C:\Users\<Username>\Source\repos\ConfigurationCore\ConfigurationCore\ConfigurationCore.csproj"
      

      enter image description here

      您会发现.nuspec已生成,请勿关闭此CMD窗口。

    5. 编辑ConfigurationCore.csproj.nuspec文件并进行修改,下面是我的.nuspec文件:

      <?xml version="1.0"?>
      <package >
        <metadata>
          <id>ConfigurationCore</id>
          <version>1.2.0</version>
          <title>Configuration Core</title>
          <authors>MAKK</authors>
          <owners>IT Department</owners>
          <requireLicenseAcceptance>false</requireLicenseAcceptance>
          <description>ConfigurationCore contains core funcationality of Software</description>
          <releaseNotes></releaseNotes>
          <copyright>Copyright 2018</copyright>
      
          <dependencies>
            <dependency id="Newtonsoft.Json" version="10.0.3" />
          </dependencies>
        </metadata>
        <files>
          <file src="C:\Users\Admin\Source\repos\ConfigurationCore\ConfigurationCore\bin\x86\Test\ConfigurationCore.dll" target="lib\net461" />
        </files>
      </package>
      
    6. 保存ConfigurationCore.csproj.nuspec文件,然后使用pack命令返回CMD窗口以生成nuget包:

      enter image description here

      ConfigurationCore.1.2.0.nupkg已创建到nuget.exe所在的文件夹D:\NuGetLocalFolder

答案 1 :(得分:1)

您的网址应以 / nuget

结尾

实施例: http://yourDomain.co/yourNuGetServer/nuget

答案 2 :(得分:0)

这是因为您引用的是非现有链接:http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0'

你在url中使用了一个无效的方法并且是导致错误的原因:

             //this is an error
../nuget/FindPackagesById()?

修复网址,测试并再试一次,

答案 3 :(得分:0)

更新您的Nuget软件包链接。

转到“项目”->“管理Nuget程序包”。

现在单击您的软件包源设置

将源链接更新为https://api.nuget.org/v3/index.json

enter image description here https://i.stack.imgur.com/sMLYn.png

答案 4 :(得分:0)

这是NuGet软件包中的连接不良的问题。将以下链接添加到NuGet包中。 https://api.nuget.org/v3/index.json Tha