Title: Provide a way to host PowerShell in a CoreCLR application · Issue #2291 · PowerShell/PowerShell · GitHub
Open Graph Title: Provide a way to host PowerShell in a CoreCLR application · Issue #2291 · PowerShell/PowerShell
X Title: Provide a way to host PowerShell in a CoreCLR application · Issue #2291 · PowerShell/PowerShell
Description: This is follow-up from #2284 Steps to reproduce Create a simple coreclr app that hosts powershell thru Microsoft.PowerShell.SDK Note: the current function of Microsoft.PowerShell.SDK is to provide an ability to compile binary modules tha...
Open Graph Description: This is follow-up from #2284 Steps to reproduce Create a simple coreclr app that hosts powershell thru Microsoft.PowerShell.SDK Note: the current function of Microsoft.PowerShell.SDK is to provide ...
X Description: This is follow-up from #2284 Steps to reproduce Create a simple coreclr app that hosts powershell thru Microsoft.PowerShell.SDK Note: the current function of Microsoft.PowerShell.SDK is to provide ...
Opengraph URL: https://github.com/PowerShell/PowerShell/issues/2291
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Provide a way to host PowerShell in a CoreCLR application","articleBody":"\u003c!--\n\nIf it is a bug report:\n- make sure you are able to repro it on the latest released version. \nYou can install the latest version from https://github.com/PowerShell/PowerShell/releases\n- Search the existing issues.\n- Refer to the [FAQ](../docs/FAQ.md).\n- Refer to the [known issues](../docs/KNOWNISSUES.md).\n- Fill out the following repro template\n\nIf it's not a bug, please remove the template and elaborate the issue in your own words.\n-->\n\nThis is follow-up from #2284\n## Steps to reproduce\n\nCreate a simple coreclr app that hosts powershell thru `Microsoft.PowerShell.SDK`\n\n**Note**: the current function of `Microsoft.PowerShell.SDK` is to provide an ability to compile binary modules that then could be imported and used in PowerShell on any platform. This issue asks a question: should we allow the same nuget package to enable **hosting** scenario?\n\nProgram.cs\n\n``` csharp\nusing System;\nusing System.Management.Automation;\n\nclass Program\n{\n static void Main(string[] args)\n {\n PowerShellAssemblyLoadContextInitializer.SetPowerShellAssemblyLoadContext(AppContext.BaseDirectory);\n\n using (var ps = PowerShell.Create())\n {\n ps.AddScript(\"Get-Process | Out-String\");\n var result = ps.Invoke()[0];\n Console.WriteLine(result.ToString());\n }\n }\n}\n```\n\nproject.json\n\n``` json\n{\n \"version\": \"1.0.0-*\",\n \"buildOptions\": {\n \"debugType\": \"portable\",\n \"emitEntryPoint\": true\n },\n \"dependencies\": {},\n \"frameworks\": {\n \"netcoreapp1.0\": {\n \"dependencies\": {\n \"Microsoft.NETCore.App\": {\n \"type\": \"platform\",\n \"version\": \"1.0.1\"\n },\n \"Microsoft.PowerShell.SDK\" : \"1.0.0-alpha10\"\n },\n \"imports\": \"dnxcore50\"\n }\n }\n}\n```\n\nnuget.config\n\n``` xml\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?>\n\u003cconfiguration>\n \u003cconfig>\n \u003c!-- install packages to a custom path -->\n \u003cadd key=\"repositoryPath\" value=\"Packages\"/>\n \u003c/config>\n \u003cpackageSources>\n \u003cclear />\n \u003cadd key=\"nuget.org\" value=\"https://api.nuget.org/v3/index.json\" />\n \u003cadd key=\"powershell-core\" value=\"https://powershell.myget.org/F/powershell-core/api/v3/index.json\" />\n \u003c/packageSources>\n\u003c/configuration>\n```\n\ndotnet restore works fine, dotnet run doesn't\n## Expected behavior\n\nYou should be able to run and execute\n## Actual behavior\n\nOn Unix (note that 6.0.0-alpha10 package doesn't have libs compile under `Unix` configuration, so that's expected)\n\n```\nUnhandled Exception: System.TypeInitializationException: The type initializer for 'System.Management.Automation.Runspaces.RunspaceFactory' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'api-ms-win-eventing-provider-l1-1-0.dll': The specified module could not be found.\n (Exception from HRESULT: 0x8007007E)\n at System.Management.Automation.Tracing.EtwActivity.UnsafeNativeMethods.EventActivityIdControl(ActivityControlCode controlCode, Guid& activityId)\n at System.Management.Automation.Tracing.EtwActivity.GetActivityId()\n at System.Management.Automation.Runspaces.RunspaceFactory..cctor()\n --- End of inner exception stack trace ---\n at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()\n at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)\n at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.Invoke()\n at Program.Main(String[] args)\n\n```\n\nOn Windows\n\n```\nUnhandled Exception: System.Management.Automation.Runspaces.PSSnapInException: Cannot load Windows PowerShell snap-in Microsoft.PowerShell.Diagnostics because of the following error: Could not load file or assembly 'Microsoft.PowerShell.Commands'. The system cannot find the file specified.\n at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadMshSnapinAssembly(PSSnapInInfo mshsnapinInfo)\n at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIn(PSSnapInInfo mshsnapinInfo)\n at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadPSSnapIns(Collection`1 mshsnapinInfos, PSConsoleLoadException& warning)\n at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.LoadConsole(PSConsoleLoadException& warning)\n at System.Management.Automation.Runspaces.RunspaceConfigForSingleShell.CreateDefaultConfiguration()\n at System.Management.Automation.Runspaces.RunspaceConfiguration.Create()\n at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace(PSHost host)\n at System.Management.Automation.Runspaces.RunspaceFactory.CreateRunspace()\n at System.Management.Automation.PowerShell.Worker.CreateRunspaceIfNeededAndDoWork(Runspace rsToUse, Boolean isSync)\n at System.Management.Automation.PowerShell.CoreInvokeHelper[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.CoreInvoke[TInput,TOutput](PSDataCollection`1 input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.CoreInvoke[TOutput](IEnumerable input, PSDataCollection`1 output, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.Invoke(IEnumerable input, PSInvocationSettings settings)\n at System.Management.Automation.PowerShell.Invoke()\n at Program.Main(String[] args)\n```\n## Environment data\n\n\u003c!-- provide the output of $PSVersionTable -->\n\n``` powershell\n> $PSVersionTable\nName Value \n---- ----- \nPSVersion 6.0.0-alpha \nPSEdition Core \nPSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} \nBuildVersion 3.0.0.0 \nGitCommitId v6.0.0-alpha.10 \nCLRVersion \nWSManStackVersion 3.0 \nPSRemotingProtocolVersion 2.3 \nSerializationVersion 1.1.0.1 \n\n```\n","author":{"url":"https://github.com/vors","@type":"Person","name":"vors"},"datePublished":"2016-09-17T16:41:29Z","url":"https://github.com/PowerShell/PowerShell/issues/2291"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:76b45dd5-1edb-d7a0-e2a5-6817137bf870 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C364:350A6F:1F91CE:2B4766:6AFD91BC |
| html-safe-nonce | b2ea6295e9724db17410e04726e84aa69b69f4bdfcd67cb4932e011b89c9bb9d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzY0OjM1MEE2RjoxRjkxQ0U6MkI0NzY2OjZBRkQ5MUJDIiwidmlzaXRvcl9pZCI6IjMwMzcyMjE3NzMzODk5NTk2MTIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 2c3d91f7c3e7fac48f2cb3f843ebd786b65b8b30a7a45254591211a45a49ed73 |
| hovercard-subject-tag | issue:177589681 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/PowerShell/PowerShell/2291/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f103b7e716cd6656af93dc1dd07b93965748c5786bfffbc6e092bb0876abf808/PowerShell/PowerShell/issues/2291 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f103b7e716cd6656af93dc1dd07b93965748c5786bfffbc6e092bb0876abf808/PowerShell/PowerShell/issues/2291 |
| og:image:alt | This is follow-up from #2284 Steps to reproduce Create a simple coreclr app that hosts powershell thru Microsoft.PowerShell.SDK Note: the current function of Microsoft.PowerShell.SDK is to provide ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | vors |
| hostname | github.com |
| expected-hostname | github.com |
| None | bc86424ef34a73b386237872800e922d149d65ba907f63d6f150a2dcb8433bea |
| turbo-cache-control | no-preview |
| go-import | github.com/PowerShell/PowerShell git https://github.com/PowerShell/PowerShell.git |
| octolytics-dimension-user_id | 11524380 |
| octolytics-dimension-user_login | PowerShell |
| octolytics-dimension-repository_id | 49609581 |
| octolytics-dimension-repository_nwo | PowerShell/PowerShell |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 49609581 |
| octolytics-dimension-repository_network_root_nwo | PowerShell/PowerShell |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 927a6c5ab1c32b38830f1b9d3050c0b9e9aa92e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width