PowerShell: Check .net runtime and .net Core SDK is installed in a machine
I love to work on brand new machines since they uncover a plethora of developer issues including code loopholes. Today, I installed the Sitecore MVP instance on a Windows 11 machine. Although the Sitecore MVP site runs on Docker, there were a few PowerShell errors when I executed the Start-Environment.ps1. These are classic errors uncovered only in a brand new machine (not necessarily Windows 11). So, here is the blog article discussing the errors and code fixes!
Since we are developers, we wish to catch exceptions in the code and provide proper messages for the user/developer rather than asking the next developer to follow instructions written in a github readme page! So, let us check the exceptions and fix the code. I have added the errors to the end of the article so that they don't disturb the flow of the article!
The Dotnet Errors are thrown due to the following line of code:
Now, no prizes for guessing the reason or solution. Since this is a brand-new machine, dotnet runtime wasn't installed and, so there is no dotnet folder under c:\program files:Executing dotnet on the cmd line also proves the same:
Add the following lines before dotnet tool restore:
There is also the url presented for download.
I installed .NET 6.0 runtime.
So, install .NET Core 3.1 SDK and that will add the following folder:
Just for reference in case if there are multiple SDK versions:
Now, run Start-Environment.ps1. Finally, all good:
PowerShell Code:
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.
At C:\mvp-site\Start-Environment.ps1:94 char:1
+ dotnet tool restore
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Error - 2:
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.
At C:\mvp-site\docker\tools\Scripts\Functions-SitecoreCLI.ps1:33 char:5
+ dotnet sitecore login --cm $CmHost --auth $IdHost --allow-write t ...
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Pushing latest items to Sitecore...
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.
At C:\mvp-site\docker\tools\Scripts\Functions-SitecoreCLI.ps1:40 char:5
+ dotnet sitecore ser push
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
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.
At C:\mvp-site\docker\tools\Scripts\Functions-SitecoreCLI.ps1:45 char:5
+ dotnet sitecore publish
+ ~~~~~~
+ CategoryInfo : ObjectNotFound: (dotnet:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
Comments
Post a Comment