Enable .NET CLI Autocomplete PowerShell

Command completion is one of the essential features in any CLI tool because it helps us be more productive and save time.

.NET

Like any other CLI tool, the .NET tool offers a CLI Autocomplete feature for PowerShell by adding a PowerShell script to the default profile ($PROFILE).

Enable Autocomplete

To enable .NET CLI Autocomplete, open a PowerShell console and run the following command.

notepad $profile

Copy the script below to the $PROFILE file that opened with the above command.

# PowerShell parameter completion shim for the dotnet CLI
Register-ArgumentCompleter -Native -CommandName dotnet -ScriptBlock {
     param($commandName, $wordToComplete, $cursorPosition)
         dotnet complete --position $cursorPosition "$wordToComplete" | ForEach-Object {
            [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
         }
 }

The result should look like this.

Save and close the profile and open a new PowerShell console.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.