microsoft / terminal

The new Windows Terminal and the original Windows console host, all in the same place!
MIT License
94.73k stars 8.2k forks source link

Importing the `OpenConsole.psm1` module should display an error message when used on Windows PowerShell 5 #17505

Open p0lyMth opened 1 month ago

p0lyMth commented 1 month ago

Windows Terminal version

1.20.11381.0

Windows build number

10.0.22631.0

Other Software

No response

Steps to reproduce

Under Developer Guidance, I made sure that I had the prerequisites:

I updated the repository with git submodule update --init --recursive

In Powershell, Import-Module .\tools\OpenConsole.psm1 works since I updated the Execution policy for my LocalMachine to run scripts. However, Set-MsBuildDevEnvironment and Invoke-OpenConsoleBuild don't work and return a CommandNotFoundException.

Expected Behavior

The following commands from Building the Code should build the application

Import-Module .\tools\OpenConsole.psm1
Set-MsBuildDevEnvironment
Invoke-OpenConsoleBuild

Actual Behavior

Instead both return:

Set-MsBuildDevEnvironment : The term 'Set-MsBuildDevEnvironment' 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 line:1 char:1
+ Set-MsBuildDevEnvironment
+ ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Set-MsBuildDevEnvironment:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
Invoke-OpenConsoleBuild : The term 'Invoke-OpenConsoleBuild' 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 line:1 char:1
+ Invoke-OpenConsoleBuild
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (Invoke-OpenConsoleBuild:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException
zadjii-msft commented 1 month ago

Which version of PowerShell are you using? "Windows PowerShell" (powershell.exe), version 5? Or PowerShell "Core" (pwsh.exe), version 7+/? (you can find this with $PSVersionTable.PSVersion)

p0lyMth commented 1 month ago

@zadjii-msft, I am using Windows PowerShell version 5:

Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22621  3672
zadjii-msft commented 1 month ago

Well yep that explains it. You need to use PowerShell 7+.

I'll convert this issue to "the powershell module should display an error if you try to import it in Powershell 5"

p0lyMth commented 1 month ago

I've installed PowerShell 7+. So I reattempted these commands:

Import-Module .\tools\OpenConsole.psm1
Set-MsBuildDevEnvironment
Invoke-OpenConsoleBuild

When I use Import-Module .\tools\OpenConsole.psm1, it works fine. However, Set-MsBuildDevEnvironment returns

Import-Module: The specified module '\Common7\Tools\Microsoft.VisualStudio.DevShell.dll' was not loaded because no valid module file was found in any module directory.

. I've included to my environment variables C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools and C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\Common7\Tools\ for MSBuild. But, still, I don't know why the above error is happening.

Invoke-OpenConsoleBuild returns

Error parsing solution file at C:\Users\<user>\Desktop\v1-logic\options-tactical\eng-cmp--dev_sec_ops\.desktop-instance\4-projects-workflow\dev_sec_ops__native\_terminal\OpenConsole.sln: Exception has been thrown by the target of an invocation.
The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less than 248 characters.
msbuild.exe: The term 'msbuild.exe' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.