dotnet-installer/Documentation/general/tool-nuget-package-format.md
2018-07-31 14:57:02 -07:00

2 KiB

Tool NuGet package format

The most straightforward way to create a .NET tool package is to run dotnet pack with PackAsTool property set in the project file. However, if your build process is highly customized, dotnet publish may not create the right package for you. In this case, you can create a NuGet package for your tool using a nuspec file and explicitly placing assets into the NuGet package following these rules.

  • The NuGet package has only /tools folder under the root and does not contain any other folders; do not include folders like /lib, /content, etc.
  • Under /tools folder, the subfolders must be structured with pattern target framework short version/RID. For example, tool assets targeting .NET core framework V2.1 that are portable across platforms should be in the folder tools/netcoreapp2.1/any.

Let's call assets under every tools/target framework short version/RID combination "per TFM-RID assets" :

  • There is a DotnetToolSettings.xml for every "per TFM-RID assets".
  • The package type is DotnetTool.
  • Each set of TFM-RID assets should have all the dependencies the tool requires to run. The TFM-RID assets should work correctly after being copied via xcopy to another machine, assuming that machine has the correct runtime version and RID environment.
  • For portable app, there must be runtimeconfig.json for every "per TFM-RID assets".

Remark:

  • Currently, only portable apps are supported so the RID must be any.
  • Only one tool per tool package.

DotnetToolSettings.xml: Example:

<?xml version="1.0" encoding="utf-8" ?>
    <DotNetCliTool>
    <Commands>
        <Command Name="%sayhello%" EntryPoint="%console.dll%" Runner="dotnet" />
    </Commands>
</DotNetCliTool>

Currently only configurable part is command name: sayhello and entry point: console.dll. Command Name is what the user will type in their shell to invoke the command. Entry point is the relative path to the entry dll with main.