vscode-powershell icon indicating copy to clipboard operation
vscode-powershell copied to clipboard

End support for PowerShell v3/v4 in VSCode-PowerShell v2.0.0

Open rjmholt opened this issue 8 years ago • 55 comments

Currently, supporting PowerShell v3 and v4 creates several challenges for us:

  • To get PSReadLine into the extension, we need changes coming in PSReadLine 2.0, which does not support v3/v4.

  • We are forced to use the v3 AST to support v3, which means:

  • Incompatibility in the APIs between v3, v4 and v5 mean that there are bugs that are hard to fix (and even hard to reproduce, since most of us don't have access to a machine running PowerShell v3 or v4).

  • Of the two CI systems we currently use and the others we are looking to invest in, none supports PowerShell v3/v4 natively.

  • v3/v4 usage is relatively low, and decreasing. With Windows Server 2019 around the corner and Server 2012 mainstream EOL also coming up this year, even more users will be moving to a newer PowerShell version.

  • The code base is fragmented and hard to maintain because:

    • We have to compile against .NET Framework 4.5.1 and .NET Standard 1.6, when we would ideally compile against only .NET Standard. (This also spurs us toward better cross platform support)
    • We also have compile time PowerShell version targets.
    • Both of which lead to crazy .csproj files like this one.
    • The .NET Framework/Standard stuff means the backend codebase is riddled with #ifdefs.
    • There are also #ifdefs for v3/v4 support.
    • There's also version conditional logic in the build and run tooling, but that's easier to work with.

This issue contains most of the discussion that's already been had about dropping v3/v4.

My suggestion is:

  • Include a deprecation warning for ~6 months, starting when v2.0.0 of the extension is released as stable.
  • Actually drop support for v3 and v4 6 months after that date.
  • Increment the major version number when we do it.
  • Ensure that PSScriptAnalyzer can analyze PowerShell feature support by version so that people can still write scripts for v3 and v4 using the VSCode extension (but with the extension host running v5+).

~Some additional things:~

  • ~An alternative to some of this is to refactor much of our code to abstract away the differences. However, that could be a costly effort and lead to significant regressions.~
  • ~We've also been talking about incrementing the major version of the extension with the addition of PSReadLine support. It seems a little cruel to me to drop v3/v4 support just as we add PSReadLine, but it also makes sense that both changes are big enough to mean a major version increase.~

UPDATE

The addition of PSReadLine depends on a new version of PSReadLine that requires PowerShell v5.1 or later. This is by far our biggest motivating factor for ending support for PowerShell v3/v4.

rjmholt avatar May 04 '18 17:05 rjmholt

Thanks for the feedback, everyone! This has been a super enlightening thread, and I was happy to hear folks chime in with their opinions at the last PowerShell Core Community Call as well.

@brwilkinson: the RFC process is intended for stuff within the PowerShell engine and language itself, this is really outside the scope, and I think we got the quality and quantity of feedback within this issue that we wanted.

In the short-term, we should write a blog post about this to enumerate our thinking in a more public way, and give folks ~6 months for us to wind down support of what will likely remain as the "1.x" extension that continues to support PS 3.x/4.x without new features.

joeyaiello avatar May 22 '18 21:05 joeyaiello

I can't keep up with all the issues!

It sounds like you've already made decisions, but I'll throw my 2 cents in here:

As long as I have to support old versions of Exchange, I need to be able to develop against old versions of PowerShell. Right now there are four versions of Exchange in play -- Exchange 2010, Exchange 2013, Exchange 2016, and Exchange 2019 (unreleased). So I develop against PS 3/4/5/5.1 and generally do it on those lab servers. Removing VSCode/PSES support for PS 3/4 will cause significant pain for me.

(And for those of you that are not aware, Exchange does not support you upgrading WMF versions. You use the version shipped with the OS where Exchange is installed.)

essentialexch avatar Jun 21 '18 17:06 essentialexch

You can still use the old version(s) of the extension without the new features... this is more to break away from that so we can have new features on the versions of PS that support them.

vexx32 avatar Jun 21 '18 18:06 vexx32

I also vote for only supporting 5.1 and Core with 2.x.

For older versions, use 1.x or use ISE or PowerShell Studio.

D3MaxT avatar Jul 10 '18 16:07 D3MaxT

Agree, it would be best to have the old extension support all PowerShell version below 5.1 and the new extension then supports from 5.1 upwards. If this would be implemented, it might be cool if a small pop-up would tell the user, if he is on 5.1 or higher, to download the newer extension.

DarkLite1 avatar Sep 20 '18 11:09 DarkLite1

I'd like to add my feedback here as well. I'm in a environment where I use a VM to do all my dev work and the only approved Windows VM is 7...So upgrading PS is impossible for me. If PS Core had better support for 7 then I could be in support of dropping it and using PS Core instead but PS Core has no plans to support Win 7 due to it going EOL soon (which my org doesn't care about, they'll still use it anyways since it's just a VM and not the main box anyways.) I'm sure I'm not the only one in a similar situation so support is still needed but separating out the extension by whether you're on 10 or Core vice older is a good idea as long as support for both is still on going for at least the next 5 years. By then, my org may actually decide we need to upgrade to 10 (hopefully).

WSLUser avatar Dec 19 '18 14:12 WSLUser

You can upgrade Windows 7 machines to PowerShell 5.1. There's no need to suffer through on v2; it's really not worth it. It's much more productive to use 5.1, there are a ton of convenience features that make it a lot simpler to work with.

vexx32 avatar Dec 19 '18 14:12 vexx32

It may be possible to update Win7 to PowerShell 5.1, but it may not be allowed.

essentialexch avatar Dec 19 '18 16:12 essentialexch

@vexx32 cough -in, -notin, @().Where(), @().ForEach(), just to name a few that make my life easier and code more readable. Plus all the bugs that have been remediated in that time so you're not working around weird issues like if blocks falling through because you did a right-hand $null compare.

@swngdnz I can see zero reason it would not be allowed. That is an issue with management more than anything technical.

morsley avatar Dec 19 '18 16:12 morsley

If it's not allowed, it's time to read up. PS v2 is such a security risk that it's a commonly-tested exploit vector for machines that have 5.1 installed and haven't fully removed v2 yet. Lots of malicious PS scripts explicitly try to use PSv2 because it's harder to protect against attacks from there, not to mention actually properly manage. If memory serves, that was before the real logging solutions were implemented, so most of them can do whatever they want without being particularly traceable.

It's not a good policy, not a safe policy by any measure of the imagination, to retain PSv2 on any company devices. I'm fighting a similar fight at my location, though in my case I'm just glad these old machines are dying off quickly enough and our replacements are all windows 10. 😄

vexx32 avatar Dec 19 '18 16:12 vexx32

I was able to upgrade but my $PSModulePath is fried. I'd hate to revert, save it somewhere, and then upgrade again. Any way to get it back?

WSLUser avatar Dec 19 '18 16:12 WSLUser

@DarthSpock PSModulePath is an environment variable. You can restore this from the "Advanced system settings" menu or using the .NET [Environment] class:

[Environment]::SetEnvironmentVariable(
    'PSModulePath',
    ("$Env:USERPROFILE\Documents\WindowsPowerShell\Modules;" +
     "$Env:ProgramFiles\WindowsPowerShell\Modules;" +
     "$Env:SystemRoot\System32\WindowsPowerShell\v1.0\Modules;"),
    [EnvironmentVariableTarget]::User
)

morsley avatar Dec 19 '18 16:12 morsley

Hi all, just want to let you know that I've been doing some work to help with the compatibility story here:

https://github.com/PowerShell/PSScriptAnalyzer/pull/1133

The next release of PSScriptAnalyzer will (with the right configuration) be able to determine that a command, .NET type or syntax in your script is not available by default on another platform (like PowerShell 3/4). So writing a script in PowerShell 5.1 or 6, you'll get advance warning that [System.Collections.ArrayList]::new() or Get-FileHash $myFile or "Stuff" | Out-File ./file.txt -NoNewline won't work in PowerShell 3/4.

I'm still writing up some documentation on how to use it, but hopefully we'll have a blog running through an example soon enough.

rjmholt avatar Feb 28 '19 23:02 rjmholt

FYI everyone, I've just published the blog post.

The compatibility rules come with the latest release of the PowerShell extension for VSCode, so all you need is to write a configuration file to run them, which is explained in the blog post.

rjmholt avatar Apr 18 '19 23:04 rjmholt

In the next release of the PowerShell extension we will be dropping support for v3/v4. For more information: https://devblogs.microsoft.com/powershell/powershell-editor-services-roadmap/

SydneyhSmith avatar Feb 06 '20 22:02 SydneyhSmith