-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better backwards compatibility w/ 5.1 #18989
Comments
As for:
There's an official page here, and I encourage you to suggest additions / corrections, as warranted: https://learn.microsoft.com/en-us/powershell/scripting/whats-new/differences-from-windows-powershell Fundamentally, the cross-edition changes fall into the following categories:
|
The gap between WinPS 5.1 and pwsh is already huge - there are probably hundreds of differences. The distance between them is increasing every day. We can assume that in 2-3 years the compatibility policy will have to be abandoned in fact. |
The PS7 version looks more generic because there is no guarantee that Last-Modified cannot have multiple values. An array of datetime looks like an alternative for the PS> [datetime[]]("2022-12-29","2023-01-20")
Thursday, December 29, 2022 12:00:00 AM
Friday, January 20, 2023 12:00:00 AM
PS> [datetime[]]"2022-12-29"
Thursday, December 29, 2022 12:00:00 AM |
In this case Last-Modified is part of rfc9110, so there is somewhat of a guarantee - https://httpwg.org/specs/rfc9110.html#rfc.section.8.8.2
|
Thank you @juliusl for taking the time to report this. PowerShell 7 is not intended to be in complete parity with Windows PowerShell 5.1. There are situations we have decided to not remain compatible. We feel that the your invoke-webrequest issue is something that should be investigated and encourage you to open it as a single issue. |
This issue has been marked as answered and has not had any activity for 1 day. It has been closed for housekeeping purposes. |
Summary of the new feature / enhancement
There are a lot of changes between PS 5.X and PS 7.X, and some of these changes make keeping scripts backwards compatible difficult,
Some examples,
Invoke-WebRequest
The return type has changed and some useful parsing has been removed. This would be mostly tolerable but currently accessing headers is a pain in 7.1 is a bit painful. For example,
API's like this would include
Last-Modified
as a header. In 5.1 this allowed direct access to the datetime via,In 7.X the return type has changed, so now it would be,
The problem is here, https://learn.microsoft.com/en-us/dotnet/api/microsoft.powershell.commands.webresponseobject.headers?view=powershellsdk-7.2.0#microsoft-powershell-commands-webresponseobject-headers, which is a
Dictionary<String, IEnumerable<String>>
.In order to make this backwards compatible, you would need to write code like this,
Set-Content
Previously,
byte
encoding was an option in theEncoding
parameter. So in 5.1, you could do this,But in 7.X, it's now,
So now to support backwards compatibility, you would need to write,
These are just two examples, and others may have some other examples, but as you can see these are very tiny inconsistencies that end up doubling code.
Proposed technical implementation details (optional)
I'm not sure how to address this problem, but I think part of the challenge is being able to collect feedback about specific backwards compat problems.
Other than that perhaps there could be some sort of polyfill solution, or some sort of dedicated module that bridges 5.1 <-> 7.X. Or maybe some code analysis rules added to the powershell language server for vscode.
If nothing else, maybe there needs to be some sort of knowledge base or wiki in this repo that documents these nuances.
I'm pretty sure it is probably too late to change binaries so maybe this is something 8.0 can address (although then there might be backwards compat issues between 7 -> 8).
The text was updated successfully, but these errors were encountered: