Feature image dotnet issue

Introduction

I encountered this issue: dotnet : The term ‘dotnet’ is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again, when tried to run dotnet add package command.

System details:
Operating System: Windows 10 Pro, Version: 22H2: , 64 bit operating system.

Error details are given below.

At line:1 char:1
+ dotnet add package Azure.AI.OpenAI –version 1.0.0-beta.9
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException

Solution

Installing just VS Code does not install .NET Core. It is needed to install the .NET Core SDK and then it should work.

If you did install .NET Core SDK already, then your PATH should point to the install location (typically in C:\Program Files\dotnet).

  1. Open PowerShell terminal as admin
  2. Run these commands in sequence to troubleshoot as shown in the picture.
  • dotnet –list-sdks
  • winget search dotnet
  • winget install –id Microsoft.DotNet.SDK.8 -e
  • cd C:\”Program Files”\dotnet
  • .\dotnet –list-sdks

3. Restart the PowerShell terminal:

  • dotnet –list-sdks

4. .NET 8 was installed successfully.

5. Make sure Environment path is updated.

6. Restart Visual Studio Code:

Conclusion

After some changes in our environment, we can see, that this command now works properly and as expected.