Nuget – Walk-through – Part 2

Creating and Publishing a Package

new-spec -AddBuildTarget

push-package

 

  1. Download NuGet.exe
  2. Make sure NuGet.exe is in your path

.csproj approach

For simple packages, creating a package from a csproj file is a convenient way to create packages.

nuget spec

nuget pack qqqq.csproj

nuget pack qqqq.csproj -IncludeReferencedProjects

nuget pack MyProject.csproj -Prop Configuration=Release

nuget pack -sym qqqq.csproj

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.
  • libAssemblies (.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.
  • build – The build folder of a package is for MSBuild targets files that are automatically inserted into the .csproj file of the application.

create the folders needed by your package and copy the correct content in each folder.

A package is considered a solution-level package if it does not contain any files in its lib, content, or build directories. If the package has dependencies, they also must not have files in their lib, content, or build directories.

When a solution-level package is installed, it is tracked in a packages.config file in the .nuget directory, rather than in a packages.config file in a specific project.

Solution level packages are not supported in NuGet 3.0.0-3.2.0, and you will need to install such packages into a common project.

 A package can include PowerShell scripts that automatically run when the package is installed or removed. NuGet automatically runs scripts based on their file names using the following conventions:
Init.ps1 runs the first time a package is installed in a solution.
Install.ps1 runs when a package is installed in a project.
Uninstall.ps1 runs every time a package is uninstalled.

At the top of your file, add this line: param($installPath, $toolsPath, $package, $project)

  • $installPath is the path to the folder where the package is installed
  • $toolsPath is the path to the tools directory in the folder where the package is installed
  • $package is a reference to the package object.
  • $project is a reference to the EnvDTE project object and represents the project the package is installed into.

When NuGet installs a package with \build files, it will add an MSBuild element in the project file pointing to the .targets and .props files. The .props file is added at the top, whereas the .targets file is added to the bottom.

A package can include a readme.txt file in the root of the package. This file will be displayed in Visual Studio immediately after the package is installed.

When NuGet installs an assembly from a package, it checks the target .NET Framework version of the project you are adding the package to.

The following example shows a .nuspec file that specifies files

The following example shows a .nuspec file that specifies framework assemblies.

nuget package explorer (GUI tool)

https://npe.codeplex.com/downloads/get/clickOnce/NuGetPackageExplorer.application

Leave a Reply

Your email address will not be published. Required fields are marked *