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>