Skip to content

Instantly share code, notes, and snippets.

What would you like to do?

Add the target below to the project file for your dotnet core global tool. You can run this target to simplify reinstalling the global tool. You can execute this target with dotnet build -t:InstallTool.

When this target is executed the following will happen (in this order):

  • Project is packed into a NuGet package
  • Tool is uninstalled with dotnet tool uninstall
  • Tool is installed with dotnet tool install
  • Help is called on the tool just installed

If you develop multiple versions you may want to edit the Exec calls below to add the version parameter.

<!-- call this target with dotnet build -t:InstallTool -->
<!-- call this target with dotnet build -t:InstallTool -->
<Target Name="InstallTool" DependsOnTargets="Pack">
      <_toolName Condition="'$(ToolCommandName)' != '' ">$(ToolCommandName)</_toolName>
    <Exec Command="dotnet tool uninstall --global $(_toolName)" IgnoreExitCode="true"/>
    <Exec Command="dotnet tool install --global --add-source $(PackageOutputPath) $(_toolName)"/>
    <Exec Command="$(ToolCommandName) --help" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment