Search code examples
nuget.net-corecsproj

.NET SDK Project Nuget Packaging: Add Tools Folder?


The new .NET SDK projects allow generating NuGet packages directly from various targets as part of the build process.

I realize that content is no longer allowed, but it looks like tools are still a viable option.

My scenario is that I need to distribute additional content after the package is installed - I understand this can't be done via NuGet anymore and that's fine. However, I want to show a Web page that has instructions for downloading and installing the additional assets.

Essentially I'd like to do something similar to what Newtonsoft.Json does:

enter image description here

I know you can use a powershell script to bring up a Web page, but is it possible to get that script into the NuGet package via the project build?


Solution

  • You can combine Pack and PackagePath item metadata.

    Example from StackExchange.Precompilation:

    <None Include="*.targets" Pack="true" PackagePath="build" />
    <None Include="App.config" Pack="true" PackagePath="tools\$(AssemblyName).exe.config" />
    

    Note, however, that install/uninstall powershell scripts are not executed anymore, since NuGet v3. The feature has been deprecated, and feature requests to add it back have been rejected. If you still want to give it a shot, your .csproj should contain something like this:

    <None Include="install.ps1" Pack="true" PackagePath="tools" />
    

    Also noteworthy:

    If you only need your assembly outputs in the tools folder (instead of lib), you can use the IsTool property.