ubuntugithub-actionsdotnet-tool

Github Action- How to restart the session?


I have a Github Action that creates a dotnet tool, and trying to use it.

$ dotnet pack MyTool.csproj --configuration Release
$ dotnet tool install --global --add-source . MyTool

Since you just installed the .NET Core SDK, you will need to logout or restart your session before running the tool you installed.
You can invoke the tool using the following command: my-tool
Tool 'MyTool' (version '1.0.0') was successfully installed.

$ my-tool

my-tool: command not found

How can I logout or restart my session in the job, to reload the PATH?


Solution

  • In the section called Install a global tool, it says that the tools are installed at the following locations:

    OS Path
    Linux/macOS $HOME/.dotnet/tools
    Windows %USERPROFILE%\.dotnet\tools

    Below that, it also says:

    This location is added to the user's path when the SDK is first run, so global tools can be invoked from any directory without specifying the tool location.

    However, it looks like from your output that you also just installed the .NET SDK so it hasn't had a chance to add those folders to the PATH.

    There are two ways of doing this that immediately come to mind:

    1. Since you already know where the tools are installed, just use the absolute path to the tool you just installed: $HOME/.dotnet/tools/my-tool

    2. Another way is to fix the PATH before running the tool so that when you get to the step that installed the tool, it is already available. In your workflow, there are many ways of modifying the PATH, but the easiest seems to be to modify the $GITHUB_PATH file. So in a previous step, do the following inside run

      run:
         ...
         mkdir --parents $HOME/.dotnet/tools
         echo "$HOME/.dotnet/tools" >> $GITHUB_PATH
      

    After this is done, the next step, should be able to access the tool after installing it.