Skip to content

Instantly share code, notes, and snippets.

@sayedihashimi
Last active February 12, 2020 23:31
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sayedihashimi/b2570698cc8cd02fe43be58e4e518042 to your computer and use it in GitHub Desktop.
Save sayedihashimi/b2570698cc8cd02fe43be58e4e518042 to your computer and use it in GitHub Desktop.

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">
    <PropertyGroup>
      <_toolName>$(MSBuildProjectName)</_toolName>
      <_toolName Condition="'$(ToolCommandName)' != '' ">$(ToolCommandName)</_toolName>
    </PropertyGroup>
    <Exec Command="dotnet tool uninstall --global $(_toolName)" IgnoreExitCode="true"/>
    <Exec Command="dotnet tool install --global --add-source $(PackageOutputPath) $(_toolName)"/>
    <Exec Command="$(ToolCommandName) --help" />
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment