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.