How to Host your own Nuget Feed? | Step by Step Guide | Tutorial

hosting-your-own-nuget-feed

Hosting your own Nuget Feed?

1. Local File Based Package Source

Limitation with fles based source –
It does not have nuget capable feed.
Can not push the package. We will have to copy into local directly
Can not use Nuget Gallery

2. Setup Nuget.Server

Step 1 – In Visual Studip, New Project and Select empty ASP.net Empty Web Application and name and save it.
Step 2 – Using Package Manager console, install package Nuget.Server.
$ install-package nuget.server
Step 3 – Look at the property of the project, under bottom part of web tab – find a port number. i.e – 42386. and open the server.
http:localhost:42386/nuget
Step 4 – Navigate the page and learn about how to user server.
Step 5 – Copy manually one nuget package and try using New NuGet Server using Visual Studip as source with http:localhost:42386/nuget
$ get-package -listavailable
Step 6 – Go to http:localhost:42386/nuget and Refresh the package feed.
Step 7 – How to access using command line – Modify the web.config and modify the apiKey as you want, Restart the application and to go http:localhost:42386/nuget to find the insructions to push the package.
$ nuget.exe push pack.nupkg -s http:localhost:42386/nuget SECRETKEY

3. Setup your Nuget Gallery

Step 1 – Download the zip software from https://github.com/NuGet/NuGetGallery

Step 2 – Unzip it under your visual studio project folder and setup with IIS.

Tools which is helpful to navigate the Nuget package feed.
LinkQPad4

Tagged : / / / / / / / / / / /

How to Publish a Nuget package in NuGet Gallery?

publish-a-nuget-package-in-nuget-gallery

How to Publish a Nuget package in NuGet Gallery?

Step 1 – Create an account at NuGet.org

Head over to http://nuget.org/ and register for an account. Once you do that, click on “My Account” to see an API Key that was generated for you.

Step 2 – In a command console, run the command:

$ nuget setApiKey Your-API-Key

This will store your API key so that you never need to do this step again on this machine.

Push your package to NuGet Gallery using the command:

$ nuget push YourPackage.nupkg

Reference
https://docs.nuget.org/consume/command-line-reference

Tagged : / / / / / / / / / / / / / /

How to create a package in Nuget? | Nuget Tutorial

create-a-package-in-nugetHosting your own Repository in Nuget

How to create a package in Nuget?

Mehtod 1 – From An Assembly
If you have an assembly, you can easily generate a nuspec file from metadata within the assembly and create a package.

$ nuget spec MyAssembly.dll

This creates a Nuspec file. Edit the NuSpec file as needed and then

$ nuget pack MyAssembly.nuspec

Mehtod 2 – Commands Lines using convention based working directory
Some packages contain more than just assemblies. They may contain

Content and source code that should be injected into the target project.
PowerShell scripts and executables.
Configuration file and source code transformations.

To create a package in this way, you can layout a directory structure that follows the NuGet conventions.

tools – The tools folder of a package is for powershell scripts and programs accessible from the Package Manager Console. After the folder is copied to the target project, it is added to the `$env:Path (PATH) environment variable.
lib – Assemblies (.dll files) in the lib folder are added as assembly references when the package is installed.
content – Files in the content folder are copied to the root of your application when the package is installed.Think of the Content folder as the root of your target application. For example, if I want a package to add an image in the /images directory of the target application, make sure to place the image in the Content/images folder of the package.
build – The build folder of a package is for MSBuild targets files that are automatically inserted into the .csproj file of the application.

Step 1- Create the manifest

$ nuget spec

This will create an XML file with the .nuspec extension.

<?xml version="1.0"?>
   <package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
   <metadata>
   <id>MyPackageId</id>
   <version>1.0</version>
   <authors>philha</authors>
   <owners>philha</owners>
   <licenseUrl>http://LICENSE_URL_HERE_OR_DELETE_THIS_LINE</licenseUrl>
   <projectUrl>http://PROJECT_URL_HERE_OR_DELETE_THIS_LINE</projectUrl>
   <iconUrl>http://ICON_URL_HERE_OR_DELETE_THIS_LINE</iconUrl>
   <requireLicenseAcceptance>false</requireLicenseAcceptance>
   <description>Package description</description>
   <tags>Tag1 Tag2</tags>
   <dependencies>
   <dependency id="SampleDependency" version="1.0" />
   </dependencies>
   </metadata>
 </package>

Edit this file to fill in the values appropriate for your package. Then create the folders needed by your package and copy the correct content in each folder.

$ mkdir lib
   $ mkdir tools
   $ mkdir content
   $ mkdir content\controllers
   $ copy ..\src\SomeController.cs content
   $ copy ..\src\MyLibrary lib
 $ copy ..\src\SomePowershellScript.ps1 tool

With the working directory in place with content, run the following command:
nuget pack YourPackage.nuspec

Mehtod 3 – Using Visual Studio Projects
For simple packages, creating a package from a csproj or vbproj file is a convenient way to create packages. For example, other packages that have been installed into your project will be referenced as dependencies when you create a package this way.

In the folder where the csproj file is, run:

$ nuget spec

This creates a special nuspec file with tokens meant to be replaced at pack time based on the project metadata. For example, $version$ gets replaced by the version specified in the AssemblyVersionAttribute (or AssemblyInformationalVersionAttribute if present) applied to your assembly (typically within the AssemblyInfo.cs file).

These tokens will only be replaced when you execute the pack command with the project file, and not with the nuspec file. The contents of the nuspec file will be located and honored, with the appropriate token replacements executed.

The following is a list of the supported replacement tokens.

Token Source
$id$ The Assembly name
$version$ The assembly version as specified in the assembly’s
AssemblyVersionAttribute (or AssemblyInformationalVersionAttribute if present).
$author$ The company as specified in the AssemblyCompanyAttribute.
$description$ The description as specified in the AssemblyDescriptionAttribute.

You can then edit this nuspec file if you need to customize it. e.g. if you don’t want token replacement for some fields, you hard code them in the nuspec instead.

Also, if you want to pull additional files into the package, you can use a node in the nuspec. e.g. suppose you want to add all the files from some arbitrary other folder into the package, you’d have:

<files>
   <file src="..\..\SomeRoot\**\*.*" target="" /> 
 </files>

You need to run ‘nuget pack’ on the project file, not the nuspec itself. But the nuspec will in fact get picked up. Once your nuspec is ready, you can run:

$ nuget pack MyProject.csproj

If the project references other projects, you can add the referenced projects as part of the package, or as dependencies with -IncludeReferencedProjects option. This is done recursively. For example, suppose you have project A.csproj, which references B.csproj and C.csproj, while B.csproj references D.csproj & E.csproj, C.csproj references F.csproj & G.csproj. Then, when you run

nuget pack A.csproj -IncludeReferencedProjects

the generated package will contain files from projects B, C, D, E, F & G, in addition to files from project A.

If a referenced project has a corresponding nuspec file with the same name, then that referenced project is added as a dependency instead. Using the same example, suppose now there is file C.nuspec in the same directory as project file C.csproj. When you run

$ nuget pack A.csproj -IncludeReferencedProjects

the generated package will contain files from projects B, D, E, in addition to files from project A, and the package has dependency on C.

By default, NuGet will use the default build configuration set in the project file (typically Debug). To pack files from a different build configuration (e.g., Release), you can run:

$ nuget pack MyProject.csproj -Prop Configuration=Release

Reference
https://docs.nuget.org/create/creating-and-publishing-a-package
https://docs.nuget.org/consume/command-line-reference

Tagged : / / / / / / / / / / / /