Skip to content

Fix use of UseShellExecute for .NET Core - #1291

Merged
Andy Jordan (andyleejordan) merged 7 commits into
masterfrom
andschwa/useshellexecute
Jul 8, 2016
Merged

Andy Jordan (andyleejordan) merged 7 commits into
masterfrom
andschwa/useshellexecute

Conversation

@andyleejordan

Copy link
Copy Markdown
Member

UseShellExecute is not supported on .NET Core because it is only MTA.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mike Richmond (@mirichmo) can anything else be done here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong) this is in PackageManagement. Do you need to do something alternative here?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong), Raghu Shantha (@raghushantha) I'm changing it for now since it will fail at runtime otherwise.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong), Raghu Shantha (@raghushantha) You guys are more familiar with this code, can you please comment on how UseShellExecute = true can be avoided here for CoreCLR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Quoc Truong (@quoctruong) Raghu Shantha (@raghushantha) please be aware this might break you.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andy Jordan (@andschwa), Dongbo Wang (@daxian-dbw) The change looks good to me.

@raghushantha Raghu Shantha (raghushantha) Jul 8, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Andy Jordan (@andschwa), Dongbo Wang (@daxian-dbw) - Only the MSU provider uses this code path. And MSU is N/A on Core platforms.

So the change is ok.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for verifying 😄

@andyleejordan

Andy Jordan (andyleejordan) commented Jul 6, 2016 •

Copy link
Copy Markdown
Member Author

Additionally, UseShellExecute defaults to true, so all direct uses of Process.Start are incorrect for CoreCLR PowerShell.

While the documentation states this fact; the code reveals a different fact.

@andyleejordan
Andy Jordan (andyleejordan) force-pushed the andschwa/useshellexecute branch 6 times, most recently from fc0cd34 to 810b3de Compare July 7, 2016 18:08
@andyleejordan

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw), Mike Richmond (@mirichmo) This ports Invoke-Item and Get-Help -Online to CoreCLR PowerShell on Windows. Please take the changes back into SD, or at least ensure the work doesn't get duplicated. Also please review and sign-off.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this looks weird. Having quotes inside of a string is blech. Since it's a string literal, each internal "" is a " so this gets interpolated as /c "start /b "" {0}" where the first "" is the empty optional title.

@daxian-dbw Dongbo Wang (daxian-dbw) Jul 7, 2016 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This command doesn't work on NanoServer/IoT. This is not supposed to work on NanoServer/IoT anyways, but we need a way to detect that browser is not available, and throw the appropriate error message in that case.

One option is to check reg key on windows to find the default browser, and use the command of the default browser to open the uri. If the reg key is not there, then that means it's NanoServer/IoT.
The reg key indicating the default browser in windows is:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice { ProgId }
get the value of ProgId and HKEY_CLASSES_ROOT\<ProgId-Value>\Shell\Open\command points to the executable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using cmd start is to avoid having to check the registry. I'm happy to leave this unimplemented for Windows and throw a platform not supported exception until the Nano team can do this properly.

@daxian-dbw Dongbo Wang (daxian-dbw) added WG-Cmdlets general cmdlet issues and removed WG-Cmdlets general cmdlet issues labels Jul 8, 2016
@daxian-dbw

Copy link
Copy Markdown
Member

There is no Nano powershell team anymore, there is only one powershell team now.
For this one, you can revert back the FullCLR powershell implementation, and throw PlatformNotSupportedException only for CoreCLR-Windows build. Then open an issue to me to fix the CoreCLR-Windows behavior including NanoServer/IoT.
But in your future code changes, please also take the NanoServer/IoT scenario into consideration. We are contributing to an open source project, so our code changes/check-ins should cover all scenarios of the project.

@andyleejordan
Andy Jordan (andyleejordan) force-pushed the andschwa/useshellexecute branch 2 times, most recently from 0c99a04 to 2332532 Compare July 8, 2016 19:36

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comment: It's always false in CoreCLR, so this line can be removed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This default is really poorly documented. That is to say, the documentation lies, so I thought I should be explicit. I can change it.

@daxian-dbw

Copy link
Copy Markdown
Member

LGTM except for some minor comments and the failed CI build.
Please remember to open an issue for the CoreCLR-windows behavior and assign it to me.
I will ping Raghu and Quoc on IM to ask them take a look.

@andyleejordan

Copy link
Copy Markdown
Member Author

Dongbo Wang (@daxian-dbw) the failing build is due to Travis updating the OS X images, and is unrelated to these changes. I'm currently investigating. Thanks for the review.

These currently fail at runtime on Nano, and will continue to do so. But
this implements these much needed cmdlets for Open PowerShell.

If there is a way to determine that PowerShell is being run on the Nano
OS at runtime, then we could instead throw a platform unsupported
exception, but this cannot be based on the target compilation framework,
as .NET Core is shared for both Nano and Windows.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

@daxian-dbw

Copy link
Copy Markdown
Member

:shipit: Thanks Andy Jordan (@andschwa) for your patience

@raghushantha

Copy link
Copy Markdown
Member

:shipit:

@andyleejordan
Andy Jordan (andyleejordan) merged commit fbc7450 into master Jul 8, 2016
@andyleejordan
Andy Jordan (andyleejordan) deleted the andschwa/useshellexecute branch July 8, 2016 21:50
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
…xecute

Fix use of UseShellExecute for .NET Core
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants