English | 日本語
DotnetToolInspector is a PowerShell module that retrieves the contents of the runtimeconfig.json for dotnet tools.
# Example of retrieving the runtimeconfig.json for the t4 command of dotnet-t4 v3.0.0
$ Get-DotnetToolRuntimeConfig -packageID "dotnet-t4" -commandName "t4"
{
"runtimeOptions": {
"tfm": "net6.0",
"rollForward": "LatestMajor",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}For example, it helps to check the required .NET SDK version to run the installed dotnet tool. This is particularly useful for determining which .NET SDK to install when using dotnet tools in GitHub Actions.
DotnetToolInspector has the following features:
- Supports global tools (
--globaland--tool-path) and local tools (--local) - Works on Ubuntu, Windows, and macOS
- Provides
action.ymlfor CI/CD usage
- PowerShell 6 or newer
Run the following command in PowerShell:
$ Install-Module -Name DotnetToolInspectorPowerShell Gallery: DotnetToolInspector
Use Get-DotnetToolRuntimeConfig to retrieve the RuntimeConfig of a dotnet tool.
Get-DotnetToolRuntimeConfig [-packageID] <string> [-commandName] <string> [[-toolPath] <string>] [-global] [-local] [<CommonParameters>]Note that the dotnet tool executable binary must be installed on the machine for it to work. For local tools, dotnet tool restore must be done beforehand.
Below is an example with dotnet-t4. Sample code is also available here.
# for 'dotnet tool install dotnet-t4 --global'
$ Get-DotnetToolRuntimeConfig -packageID "dotnet-t4" -commandName "t4" -global
{
"runtimeOptions": {
"tfm": "net6.0",
"rollForward": "LatestMajor",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}
# for 'dotnet tool install dotnet-t4 --tool-path <path-to-your-tool-path>'
$ Get-DotnetToolRuntimeConfig -packageID "dotnet-t4" -commandName "t4" -toolPath "path\to\your\tool-path"
{
"runtimeOptions": {
"tfm": "net6.0",
"rollForward": "LatestMajor",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}# for 'dotnet tool install dotnet-t4 --local'
$ Get-DotnetToolRuntimeConfig -packageID "dotnet-t4" -commandName "t4"
{
"runtimeOptions": {
"tfm": "net6.0",
"rollForward": "LatestMajor",
"framework": {
"name": "Microsoft.NETCore.App",
"version": "6.0.0"
},
"configProperties": {
"System.Reflection.Metadata.MetadataUpdater.IsSupported": false
}
}
}Sample code is available here.
name: Sample
on: workflow_dispatch
jobs:
sample:
name: Sample
runs-on: ubuntu-latest
steps:
# Checkout Sample Data
- name: check out
uses: actions/checkout@v4
# Check .NET SDK Version
- name: Example -toolPath
id: toolpath
uses: hanachiru/DotnetToolInspector@main
with:
package-id: dotnet-t4
command-name: t4
tool-path: ./Tests/Data/tool-path
# Setup .NET
- name: Setup Dotnet
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ steps.toolpath.outputs.framework-version-major }}If you want to retrieve information about local tools, make sure to run dotnet tool restore beforehand.
- name: dotnet tool restore
working-directory: ./Tests/Data/local
run: |
dotnet tool restore
- name: Example -local
uses: hanachiru/DotnetToolInspector@main
with:
package-id: dotnet-t4
command-name: t4
working-directory: ./Tests/Data/localSet global: true if you want to use -global.
- name: dotnet tool install
run: |
dotnet tool install dotnet-t4 --global
- name: Example -global
uses: hanachiru/DotnetToolInspector@main
with:
package-id: dotnet-t4
command-name: t4
global: trueThe following environment variables can modify the behavior. For details, refer to the official documentation.
| Environment Variable | Description | Default Value |
|---|---|---|
| DOTNET_CLI_HOME | Specifies the location where supporting files for .NET CLI commands should be written. | Default value for each OS |
| NUGET_PACKAGES | Configures a path to the NuGet global-packages folder. |
Default value for each OS |
The default values of the DOTNET_CLI_HOME and NUGET_PACKAGES environment variables depend on the operating system used on the runner:
| Operating System | DOTNET_CLI_HOME |
NUGET_PACKAGES |
|---|---|---|
| Windows | %userprofile%\.dotnet\tools |
%userprofile%\.nuget\packages |
| Ubuntu | ~/.dotnet/tools |
~/.nuget/packages |
| macOS | ~/.dotnet/tools |
~/.nuget/packages |