Not sure what exactly I am doing wrong. I have some PS1 scripts I use in Visual Studio Code (no POSH-Tools there, just regular PowerShell extension). When I copy the script to Visual Studio, I run into two problems:
1.) Visual Studio claims there are tons of missing closing brackets and unexpected tokens (brackets and ? amongst them). This is just not true, no other environment complains about the syntax - and when running the script in VIsual Studio, it generally works, but
2.) this is a part of my code:
$x = Read-Host "Please confirm ..."
This super simple line results in some funny error message:
[ERROR] Read-Host: Script.ps1:189
[ERROR] Line |
[ERROR] 189 | $x = Read-Host "Please confirm …
[ERROR] | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[ERROR] | The calling thread must be STA, because many UI components require this.
Google supposed I turn on the STA option which I did. Restarted VS, and the errors are gone - but so is all the syntax highlighting and IntelliSense. Disabled STA again, still does not work. Also cleared the contents of Appdata\Local\Microsoft\VisualStudio\16.0\ComponentModelCache - without any success.
Any suggestions? I’m using the demo license with PS7 btw.
As this only happens in Visual Studio I would assume it has something to do with the POSH-Tools. Would be nice to see everything working properly before purchasing licenses. Anyone has an idea what the issues might be here?
This is a screenshot of the syntax highlighting not working:
We’re releasing a fix for the parsing errors. The problem was that even though it was using PS7 for execution and intellisense the error tagging was still happening in PS5.
And for the STA issue, you will have to change the setting in the Options dialog here.
I’ve checked the STA setting in PowerShell Tools options, Powershell Version is set to "Windows PowerShell (x64), but the error is still there.
I am using VS 2019 Enterprise, PowerShell Tools Pro (latest verison), PS 7.0.2 x64 is installed, too.