Fork me on GitHub

How to build and install nuget packages (.nupkg) from sources ?

Gentoo Mono Handbook
 
.nuspec manifest is used to build a package and is also stored in the package after the package is built.

How to include a NuGet package in a MonoDevelop Project
    https://developer.xamarin.com/guides/cross-platform/application_fundamentals/nuget_walkthrough/

Typical .nuspec file

<?xml version="1.0"?>
<package >
  <metadata>
    <id>$package_id$</id>
    <version>$package_version$</version>
    <authors>$package_authors$</authors>
    <owners>$package_owners$</owners>
    <licenseUrl>$package_licenseUrl$</licenseUrl>
    <projectUrl>$package_ProjectUrl$</projectUrl>
    <iconUrl>$package_iconUrl$</iconUrl>
    <requireLicenseAcceptance>false</requireLicenseAcceptance>
    <description>$package_description$</description>
    <releaseNotes>$package_releaseNotes$</releaseNotes>
    <copyright>$package_copyright$</copyright>
    <tags>$package_tags$</tags>
    <!--
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
    -->
  </metadata>
  <!-- the package element can include a files element that specifies files to be included in the package.
  If the files element is omitted, all files and folders that are 
  in the same folder as the .nuspec file are included in the package.
  (q) https://docs.nuget.org/create/nuspec-reference-->
</package>

replacement tokens and properties

https://docs.nuget.org/ndocs/schema/nuspec
-Properties
Provides the ability to specify a semicolon ";" delimited list of properties when creating a package.
If one set Properties twice, then nuget will give the error:
Invalid option value: '-Properties package_version=4.1.3'
And this is not very good, because it become more difficult to provide default values for that properties

When you build the package by using MSBuild, the properties defined for the build propagate through to the package build as values for replacement tokens. They will have the same names as the properties in MSBuild, which makes it possible to select files to be included depending on the current build configuration. For instance:
<files>
    <file src="bin\$configuration$\$id$.pdb" target="lib\net40\" />
</files>

How to set version

Replace specified version
<version>1.0.0</version>
with replacement token:
        <version>$version$</version>
specify the property through nuget command line arguments in the ebuild:
	enuspec -Prop version=4.1.3 ./src/NuGet/NLog/NLog.nuspec

Pack command

https://docs.nuget.org/Consume/Command-Line-Reference#pack-command
The .nuspec file is included in the package after the package is built (but without the element that lists files if that element was included).

So, we need to copy file from ${FILESDIR} into output dir, and thus we will be able to use defaults.

or just add locations with a patch

How to create .nuspec file

In the folder where the csproj file is, run:
nuget spec

# nuget spec SharpHsql.csproj 
Created 'SharpHsql.csproj.nuspec' successfully.
The file will have following content:
<?xml version="1.0"?>
<package >
  <metadata>
    <id>NLog.mono4.csproj</id>
    <version>1.0.0</version>
    <authors>user</authors>
    <owners>user</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>
    <releaseNotes>Summary of changes made in this release of the package.</releaseNotes>
    <copyright>Copyright 2015</copyright>
    <tags>Tag1 Tag2</tags>
    <dependencies>
      <dependency id="SampleDependency" version="1.0" />
    </dependencies>
  </metadata>
</package>

Default paths

you generate a blank nuspec file with:
nuget spec
If you use that file and then put your dlls in a folder under it named lib, it will package them up.
If you manually reference any files in the nuspec file, the conventions are not used.
you can tell nuget the location of your .\lib folder via the -BasePath command line:
build\nuget.exe pack nuget\Company.Project.nuspec -BasePath nuget\

You'll run NuGet on a single project (or nuspec file), but it supports pointers to other projects via the file element.
This element uses the names of your project's References, so you avoid having to
a) find the location of other project files, and
b) copy files to a particular place as a post-build step.
Supposing you have a nuspec file for MyLibrary.Core.csproj, and it references MyLibrary.Extensions and MyLibrary.Tests such that they end up in the bin directory after a build:

<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
<metadata>
...
</metadata>
<files>
<file src="bin\Release\MyLibrary.Extensions.dll" target="lib\net40" />
<file src="bin\Release\MyLibrary.Tests.dll" target="lib\net40" />
</files>
</package>


With this setup, all of your references should end up in the appropriate place in the NuGet package.
You still have the hard-coded 'Release' in there, but I'd wager most probably don't distribute NuGet packages of their debug builds anyway.

Debug and Release configurations

https://github.com/mrward/monodevelop-nuget-addin/issues/62