This repository was archived by the owner on Dec 3, 2025. It is now read-only.
Repository navigation
WIP Initial PowerShelll kernel prototype #751
Closed
TylerLeonhardt
wants to merge
3
commits into
dotnet:master
from
TylerLeonhardt:add-powershell-kernel
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
Microsoft.DotNet.Interactive.PowerShell/Commands/CommandUtils.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using System.Management.Automation; | ||
| using Microsoft.PowerShell.Commands; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.PowerShell.Commands | ||
| { | ||
| internal class CommandUtils | ||
| { | ||
| internal readonly static CmdletInfo OutStringCmdletInfo = new CmdletInfo("Out-String", typeof(OutStringCommand)); | ||
| internal readonly static CmdletInfo WriteInformationCmdletInfo = new CmdletInfo("Write-Information", typeof(WriteInformationCommand)); | ||
|
|
||
| internal readonly static object BoxedTrue = (object)true; | ||
| internal readonly static object BoxedFalse = (object)false; | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
Microsoft.DotNet.Interactive.PowerShell/Commands/TracePipelineObjectCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
| // | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using Microsoft.PowerShell.Commands; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.PowerShell.Commands | ||
| { | ||
| using System.Management.Automation; | ||
|
|
||
| /// <summary> | ||
| /// Writes the formatted output of the pipeline object to the information stream before passing the object down to the pipeline. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This Cmdlet behaves like 'Tee-Object'. | ||
| /// An input pipeline object is first pushed through a steppable pipeline that consists of 'Out-String | Write-Information -Tags "__PipelineObject__"', | ||
| /// and then it's written out back to the pipeline without change. In this approach, we can intercept and trace the pipeline objects in a streaming way | ||
| /// and keep the objects in pipeline at the same time. | ||
| /// </remarks> | ||
| [Cmdlet(VerbsDiagnostic.Trace, "PipelineObject")] | ||
| public sealed class TracePipelineObjectCommand : PSCmdlet | ||
| { | ||
| /// <summary> | ||
| /// The object from pipeline. | ||
| /// </summary> | ||
| [Parameter(Mandatory = true, Position = 0, ValueFromPipeline = true)] | ||
| public object InputObject { get; set; } | ||
|
|
||
| private static PowerShell s_pwsh; | ||
| private SteppablePipeline _stepPipeline; | ||
|
|
||
| static TracePipelineObjectCommand() | ||
| { | ||
| s_pwsh = PowerShell.Create(); | ||
| s_pwsh.AddCommand(CommandUtils.OutStringCmdletInfo).AddParameter("Stream", CommandUtils.BoxedTrue) | ||
| .AddCommand(CommandUtils.WriteInformationCmdletInfo).AddParameter("Tags", "__PipelineObject__"); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// BeginProcessing override. | ||
| /// </summary> | ||
| protected override void BeginProcessing() | ||
| { | ||
| _stepPipeline = s_pwsh.GetSteppablePipeline(); | ||
| _stepPipeline.Begin(this); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// ProcessRecord override. | ||
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| _stepPipeline.Process(InputObject); | ||
| WriteObject(InputObject); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// EndProcessing override. | ||
| /// </summary> | ||
| protected override void EndProcessing() | ||
| { | ||
| _stepPipeline.End(); | ||
| } | ||
| } | ||
| } | ||
27 changes: 27 additions & 0 deletions
27
Microsoft.DotNet.Interactive.PowerShell/Microsoft.DotNet.Interactive.PowerShell.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netcoreapp3.1</TargetFramework> | ||
| <NoWarn>$(NoWarn);2003;CS8002;NU1608;</NoWarn> <!-- AssemblyInformationalVersionAttribute contains a non-standard value --> | ||
| <Deterministic Condition="'$(NCrunch)' == '1'">false</Deterministic> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'"> | ||
| <NoWarn>;NU5104;2003;8002</NoWarn> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\Microsoft.DotNet.Interactive.Formatting\Microsoft.DotNet.Interactive.Formatting.csproj" /> | ||
| <ProjectReference Include="..\Microsoft.DotNet.Interactive\Microsoft.DotNet.Interactive.csproj" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0-rc.1" /> | ||
| </ItemGroup> | ||
| <ItemGroup> | ||
| <Content Include="Modules\**" PackageCopyToOutput="true"> | ||
| <Link>Modules\%(RecursiveDir)\%(FileName)%(Extension)</Link> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| </Content> | ||
| </ItemGroup> | ||
| </Project> |
131 changes: 131 additions & 0 deletions
131
...ules/Microsoft.DotNet.Interactive.PowerShell/Microsoft.DotNet.Interactive.PowerShell.psd1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # | ||
| # Module manifest for module 'Microsoft.DotNet.Interactive.PowerShell' | ||
| # | ||
| # Generated by: tyleonha | ||
| # | ||
| # Generated on: 1/23/2020 | ||
| # | ||
|
|
||
| @{ | ||
|
|
||
| # Script module or binary module file associated with this manifest. | ||
| # RootModule = '' | ||
|
|
||
| # Version number of this module. | ||
| ModuleVersion = '0.0.1' | ||
|
|
||
| # Supported PSEditions | ||
| # CompatiblePSEditions = @() | ||
|
|
||
| # ID used to uniquely identify this module | ||
| GUID = 'c3ca4cca-fd49-4b1e-a79e-b12afb026068' | ||
|
|
||
| # Author of this module | ||
| Author = 'Microsoft Corporation' | ||
|
|
||
| # Company or vendor of this module | ||
| CompanyName = 'Microsoft Corporation' | ||
|
|
||
| # Copyright statement for this module | ||
| Copyright = '(c) Microsoft Corporation. All rights reserved.' | ||
|
|
||
| # Description of the functionality provided by this module | ||
| # Description = '' | ||
|
|
||
| # Minimum version of the PowerShell engine required by this module | ||
| # PowerShellVersion = '' | ||
|
|
||
| # Name of the PowerShell host required by this module | ||
| # PowerShellHostName = '' | ||
|
|
||
| # Minimum version of the PowerShell host required by this module | ||
| # PowerShellHostVersion = '' | ||
|
|
||
| # Minimum version of Microsoft .NET Framework required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | ||
| # DotNetFrameworkVersion = '' | ||
|
|
||
| # Minimum version of the common language runtime (CLR) required by this module. This prerequisite is valid for the PowerShell Desktop edition only. | ||
| # CLRVersion = '' | ||
|
|
||
| # Processor architecture (None, X86, Amd64) required by this module | ||
| # ProcessorArchitecture = '' | ||
|
|
||
| # Modules that must be imported into the global environment prior to importing this module | ||
| # RequiredModules = @() | ||
|
|
||
| # Assemblies that must be loaded prior to importing this module | ||
| # RequiredAssemblies = @() | ||
|
|
||
| # Script files (.ps1) that are run in the caller's environment prior to importing this module. | ||
| # ScriptsToProcess = @() | ||
|
|
||
| # Type files (.ps1xml) to be loaded when importing this module | ||
| # TypesToProcess = @() | ||
|
|
||
| # Format files (.ps1xml) to be loaded when importing this module | ||
| # FormatsToProcess = @() | ||
|
|
||
| # Modules to import as nested modules of the module specified in RootModule/ModuleToProcess | ||
| NestedModules = @('Microsoft.DotNet.Interactive.PowerShell.dll') | ||
|
|
||
| # Functions to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no functions to export. | ||
| FunctionsToExport = @() | ||
|
|
||
| # Cmdlets to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no cmdlets to export. | ||
| CmdletsToExport = @('Trace-PipelineObject') | ||
|
|
||
| # Variables to export from this module | ||
| VariablesToExport = '*' | ||
|
|
||
| # Aliases to export from this module, for best performance, do not use wildcards and do not delete the entry, use an empty array if there are no aliases to export. | ||
| AliasesToExport = @() | ||
|
|
||
| # DSC resources to export from this module | ||
| # DscResourcesToExport = @() | ||
|
|
||
| # List of all modules packaged with this module | ||
| # ModuleList = @() | ||
|
|
||
| # List of all files packaged with this module | ||
| # FileList = @() | ||
|
|
||
| # Private data to pass to the module specified in RootModule/ModuleToProcess. This may also contain a PSData hashtable with additional module metadata used by PowerShell. | ||
| PrivateData = @{ | ||
|
|
||
| PSData = @{ | ||
|
|
||
| # Tags applied to this module. These help with module discovery in online galleries. | ||
| # Tags = @() | ||
|
|
||
| # A URL to the license for this module. | ||
| # LicenseUri = '' | ||
|
|
||
| # A URL to the main website for this project. | ||
| # ProjectUri = '' | ||
|
|
||
| # A URL to an icon representing this module. | ||
| # IconUri = '' | ||
|
|
||
| # ReleaseNotes of this module | ||
| # ReleaseNotes = '' | ||
|
|
||
| # Prerelease string of this module | ||
| # Prerelease = '' | ||
|
|
||
| # Flag to indicate whether the module requires explicit user acceptance for install/update/save | ||
| # RequireLicenseAcceptance = $false | ||
|
|
||
| # External dependent modules of this module | ||
| # ExternalModuleDependencies = @() | ||
|
|
||
| } # End of PSData hashtable | ||
|
|
||
| } # End of PrivateData hashtable | ||
|
|
||
| # HelpInfo URI of this module | ||
| # HelpInfoURI = '' | ||
|
|
||
| # Default prefix for commands exported from this module. Override the default prefix using Import-Module -Prefix. | ||
| # DefaultCommandPrefix = '' | ||
|
|
||
| } |
67 changes: 67 additions & 0 deletions
67
Microsoft.DotNet.Interactive.PowerShell/PowerShellExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| // Copyright (c) .NET Foundation and contributors. All rights reserved. | ||
| // Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
|
||
| using System.Collections; | ||
| using System.Collections.ObjectModel; | ||
|
|
||
| namespace Microsoft.DotNet.Interactive.PowerShell | ||
| { | ||
| using System.Management.Automation; | ||
|
jonsequitur marked this conversation as resolved.
Resolved
|
||
|
|
||
| internal static class PowerShellExtensions | ||
| { | ||
| public static void InvokeAndClearCommands(this PowerShell pwsh) | ||
| { | ||
| try | ||
| { | ||
| pwsh.Invoke(); | ||
| } | ||
| finally | ||
| { | ||
| pwsh.Streams.ClearStreams(); | ||
| pwsh.Commands.Clear(); | ||
| } | ||
| } | ||
|
|
||
| public static void InvokeAndClearCommands(this PowerShell pwsh, IEnumerable input) | ||
| { | ||
| try | ||
| { | ||
| pwsh.Invoke(input); | ||
| } | ||
| finally | ||
| { | ||
| pwsh.Streams.ClearStreams(); | ||
| pwsh.Commands.Clear(); | ||
| } | ||
| } | ||
|
|
||
| public static Collection<T> InvokeAndClearCommands<T>(this PowerShell pwsh) | ||
| { | ||
| try | ||
| { | ||
| var result = pwsh.Invoke<T>(); | ||
| return result; | ||
| } | ||
| finally | ||
| { | ||
| pwsh.Streams.ClearStreams(); | ||
| pwsh.Commands.Clear(); | ||
| } | ||
| } | ||
|
|
||
| public static Collection<T> InvokeAndClearCommands<T>(this PowerShell pwsh, IEnumerable input) | ||
| { | ||
| try | ||
| { | ||
| var result = pwsh.Invoke<T>(input); | ||
| return result; | ||
| } | ||
| finally | ||
| { | ||
| pwsh.Streams.ClearStreams(); | ||
| pwsh.Commands.Clear(); | ||
| } | ||
| } | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.