Remoting apparently depends on the names of private fields
not changing between versions of PowerShell.
Because of this, these refactorings broke remoting:
* rename private fields
* convert to auto-property
If the attempt to get the name fails, throwing an exception results in
PowerShell crashing. Instead, we should simply return empty data.
"unknown" is specifically not returned because it would be ambiguous; it
is not impossible to have an actual user or domain named "unknown".
Root cause: Microsoft.WSMan.Management and Microsoft.PowerShell.Commands.Diagnostics are not put in the default snapin list for win-ops, and thus when a runspace is created using RunspaceConfiguration, those 2 are not loaded as snapins by default, which is a behavior change compared to Nano PS.
Fix: Replace the guard 'PORTABLE' to be 'UNIX' so that they are in the default snapin list when targeting windows platform.
Mostly using R# to automatically refactor, with some manual
fixups where it wouldn't work automatically (e.g. xml comments
on fields) or some it seemed to miss.
Some minor code reformatting was also done on properties near
other stuff I was manually inspecting.
alpha04 has following changes:
- libmi.so is not included in this package. It will be brough
as a separate nuget package later.
- all unix runtimes are replaced by generic unix runtimes to
enable easier builds on new unix platforms.
Fix#1465
On Linux, it's common to use error stream (2) as an information stream.
There is no errors in this case, it's just a way to report info.
When PowerShell redirects error stream, it wraps all output from stream 2
in NativeCommandError ErrorRecord.
That doesn't happen for interactive experience (when there is no
redirection), but it shows up in logs, scripting and non-console
powershell hosts (i.e. PowerShell ISE).
Here we change the formatter, so we are keeping the ErrorRecords
objects, but we are changing their default representation.
If it's a NativeCommandError, we don't use the regular ErrorRecord
formatter. It allows us keep ErrorRecord object,
but in redirection case it will look exectly like on the screen.
Also, we are change NativeCommandErrorMessage to use one line per
ErrorRecord to enable this scenario.
We use a lot of reflection, and when you rename a member (e.g. when running
the code formatter), it doesn't detect references where you're using reflection.
By using nameof(), we can now find these references (e.g. a build break) instead
of failing at runtime.
I (Jason Shirk) ran https://github.com/dotnet/codeformatter with the default rules, basically:
codeformatter /nocopyright "/c:DEBUG,UNIX,CORECLR" @files.rsp
This caused a few problems building, which were fixed up manually.
Notable changes:
`this.` is removed unless needed to disambiguate.
private instance fields are renamed to have a `_` prefix.
private static fields are renamed to have a `s_` prefix.
I left some projects alone (like PackageManagement) and also left some generated code alone.