7

Trying to generate a Nuget Package from dll. One of our project is generating ConfigurationCore.dll and References of project assemblies given below

  • Microsoft.CSharp
  • Newtonsoft.Json
  • Mak.Enums (Custom Nuget Package available on local Nuget Server)
  • Mak.Operations (Custom Nuget Package available on local Nuget Server)
  • 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

Using below ConfigurationCore.nuspec to generate Nuget Package

<?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>

Attempting to gather dependency information for package 'ConfigurationCore.1.2.0' with respect to project 'NugetTest', targeting '.NETFramework,Version=v4.6.1' Gathering dependency information took 1.09 sec Attempting to resolve dependencies for package 'ConfigurationCore.1.2.0' with DependencyBehavior 'Lowest' Resolving dependency information took 0 ms Resolving actions to install package 'ConfigurationCore.1.2.0' Resolved actions to install package 'ConfigurationCore.1.2.0' The V2 feed at 'http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0' returned an unexpected status code '404 Not Found'. Time Elapsed: 00:00:02.1513344 ========== Finished ==========

Note: The Nuget package source is on local harddrive... Please advise to fix the issue.

Joseph Cenk
  • 107
  • 1
  • 1
  • 7

6 Answers6

19

Update your Nuget package link.

Go to Project -> Manage Nuget Packages.

Now click on your package source settings.

Update Source Link to https://api.nuget.org/v3/index.json

Screenshot of the example settings as explained above.

Wouter
  • 534
  • 3
  • 14
  • 22
Munirul Islam
  • 191
  • 1
  • 4
6

Your URL should end with /nuget

Example: http://yourDomain.co/yourNuGetServer/nuget

Marouane Afroukh
  • 2,783
  • 2
  • 14
  • 9
4

This is problem of bad connection in the NuGet package. Add the following link into the NuGet Package. https://api.nuget.org/v3/index.json Tha

2

Nuget returned an unexpected status code '404 Not Found' - Package on local drive

  1. Make sure the path in the src="..." is correct.

    Perhaps the path should be:

    ...\ConfigurationCore\ConfigurationCore\... rather than ...\ConfigurationCore\....

    In short, make sure you can find the dll file base on that url.

    Note: Generally, we recommend using relative paths in url, like:

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

  2. Update the version of nuget.exe.

    There is an issue on the nuget.exe 3.4.x, so please download nuget.exe 3.5 and above.

See Create nuget package from dlls for more detailed info.

Update: Please following below steps to create the nuget package:

  1. Download the nuget.exe, and set it on your local, for example, D:\NuGetLocalFolder.

  2. Create a new project with project name "ConfigurationCore".

  3. Open a cmd and switch to the path where nuget.exe was stored previously.

  4. Use command line:

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

    enter image description here

    You will find the .nuspec be genererated, Do not close this CMD window.

  5. Edit the ConfigurationCore.csproj.nuspec file and modify it, below is my .nuspec file:

    <?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. Save ConfigurationCore.csproj.nuspec file, and back to your CMD window, using pack command to generate the nuget package:

    enter image description here

    The package ConfigurationCore.1.2.0.nupkg was created into the folder where nuget.exe exists, D:\NuGetLocalFolder.

Leo Liu
  • 71,098
  • 10
  • 114
  • 135
  • When I am using relative Path(bin\x86\Test\ConfigurationCore.dll), Nuget pack is throwing error like File not found. – Joseph Cenk Jan 16 '18 at 09:36
  • Where is your `.nuspec` file? If you using this relative Path, you should set the `.nuspec` file in the project folder, in the same folder of `.csproj` file. Right click on your project not solution, select open folder in the file explorer. Set your `.nuspec` file here. – Leo Liu Jan 16 '18 at 09:42
  • Again, the relative path depends on where your `.nuspec` file is located. You can follow the detailed steps in the second method in the accepted answer: https://stackoverflow.com/questions/43277715/create-nuget-package-from-dlls/43316056#43316056 – Leo Liu Jan 16 '18 at 09:48
  • yes, nuget.exe & .nuspec are in same project folder... but still Nuget pack is throwing error like File not found... – Joseph Cenk Jan 16 '18 at 10:06
  • @JosephCenk, I have updated my answer with some detailed steps, you can follow those steps to create nuget package, please check if that help you. – Leo Liu Jan 17 '18 at 02:14
  • @JosephCenk, How about this issue now? Have you resolve this issue? If not, please let me know the latest status info. – Leo Liu Jan 18 '18 at 01:30
  • Thanks for you support, issue has been solved... I just removed http://builtsrv1:8080/nuget & it worked... – Joseph Cenk Jan 18 '18 at 06:04
  • @JosephCenk, I`m glad that you have resolved this issue. You could post your solution to a answer, so it could help other community members who get the same issues. Thanks. – Leo Liu Jan 19 '18 at 01:34
1

This can happen because you are supplying a "nuget v3" url when only a "nuget v2" url is supported (in my case apt-get was giving me some ancient version of nuget). Typically a nuget source that supports v3 will also support v2, so if your url looks like

https://<something>/api/v3/index.json

try changing it to

https://<something>/api/v2
Tom Carver
  • 962
  • 7
  • 17
0

This is because you are referencing a non existing link: http://builtsrv1:8080/nuget/FindPackagesById()?id='ConfigurationCore'&semVerLevel=2.0.0'

You are using a method inside url, which is invalid and is the cause for the mistake:

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

fix the url, test it and try again,

Barr J
  • 10,636
  • 1
  • 28
  • 46