Skip to content
This repository was archived by the owner on Apr 27, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
542a675
add PowerShell subkernel
TylerLeonhardt Jan 23, 2020
8e41f9e
simplify code and address feedback
TylerLeonhardt Jan 23, 2020
36f2ec3
misc cleanup
TylerLeonhardt Jan 23, 2020
1e0754a
add empty test project like csharp
TylerLeonhardt Jan 24, 2020
b7668fc
Add test project to sln
TylerLeonhardt Jan 24, 2020
df9ef5b
fix up psd1 and update headers
TylerLeonhardt Jan 24, 2020
ba3d16d
PR feedback
TylerLeonhardt Jan 27, 2020
ff4ac7c
analyzer fixes
TylerLeonhardt Jan 27, 2020
f73e071
additional comment
TylerLeonhardt Jan 27, 2020
0802ffe
remove manditory from InputObject
TylerLeonhardt Jan 28, 2020
6c8095e
handle parse errors and fix trace-pipelineobjectcommand param
TylerLeonhardt Jan 29, 2020
bcf0295
signing file change
TylerLeonhardt Jan 29, 2020
24b0ced
whitespace
TylerLeonhardt Jan 29, 2020
dd2a0c6
one more signing
TylerLeonhardt Jan 29, 2020
d4b3018
change to none
TylerLeonhardt Jan 29, 2020
3bc49d7
remove IExtensibleKernel for now until we understand what we want tha…
TylerLeonhardt Jan 29, 2020
8d61e78
some tests and small changes to formatting
TylerLeonhardt Jan 29, 2020
1913ea2
refactor tests
TylerLeonhardt Jan 29, 2020
e3839bb
powershell telemetry & hook up forgotten Progress stream
TylerLeonhardt Jan 29, 2020
9ae44d5
updating progresses!
TylerLeonhardt Jan 30, 2020
807977c
add progress test
TylerLeonhardt Jan 30, 2020
dfcded8
help for ci failures
TylerLeonhardt Jan 30, 2020
9318b4e
exclude files from symbols packages
brettfo Jan 30, 2020
bc99793
rewrite package file stripper in pure MSBuild for cross-plat
brettfo Jan 31, 2020
1cb3994
workaround PowerShell bug
TylerLeonhardt Jan 31, 2020
ed4dac7
Jon feedback
TylerLeonhardt Jan 31, 2020
d9f25ab
remove timeout on new tests
TylerLeonhardt Jan 31, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Microsoft.DotNet.Interactive.Jupyter/Protocol/LanguageInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public FSharpLanguageInfo(string version = "4.5") : base("C#", version, "text/x-
}
}

public class PowerShellLanguageInfo : LanguageInfo
{
public PowerShellLanguageInfo(string version = "7.0") : base("PowerShell", version, "text/x-powershell", ".ps1", pygmentsLexer: "powershell")
{

}
}

public class VBnetLanguageInfo : LanguageInfo
{
public VBnetLanguageInfo(string version = "15.0") : base("C#", version, "text/x-vbnet", ".vb", pygmentsLexer: "vbnet")
Expand Down
1 change: 1 addition & 0 deletions Microsoft.DotNet.Interactive.Jupyter/Shell.cs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ private LanguageInfo GetLanguageInfo(string kernelName) =>
{
"csharp" => new CSharpLanguageInfo(),
"fsharp" => new FSharpLanguageInfo(),
"powershell" => new PowerShellLanguageInfo(),
_ => null
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>latest</LangVersion>
<Deterministic Condition="'$(NCrunch)' == '1'">false</Deterministic>
Comment thread
TylerLeonhardt marked this conversation as resolved.
Resolved
</PropertyGroup>

<ItemGroup>
<Compile Remove="TestResults\**" />
<Compile Remove="TestProjects\**" />
<EmbeddedResource Remove="TestResults\**" />
<None Remove="TestResults\**" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.DotNet.Interactive.PowerShell\Microsoft.DotNet.Interactive.PowerShell.csproj" />
</ItemGroup>

</Project>
17 changes: 17 additions & 0 deletions Microsoft.DotNet.Interactive.PowerShell/Commands/CommandUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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.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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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.

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)]
[AllowNull]
public object InputObject { get; set; }

private static PowerShell _pwsh;
private SteppablePipeline _stepPipeline;

static TracePipelineObjectCommand()
{
_pwsh = PowerShell.Create();
_pwsh.AddCommand(CommandUtils.OutStringCmdletInfo).AddParameter("Stream", CommandUtils.BoxedTrue)
.AddCommand(CommandUtils.WriteInformationCmdletInfo).AddParameter("Tags", "__PipelineObject__");
}

/// <summary>
/// BeginProcessing override.
/// </summary>
protected override void BeginProcessing()
{
_stepPipeline = _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();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Comment thread
TylerLeonhardt marked this conversation as resolved.
Resolved
<LangVersion>latest</LangVersion>
<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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
# 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.

@{
# Version number of this module.
ModuleVersion = '0.1.0'

# Supported PSEditions
CompatiblePSEditions = @('Core')

# 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 = 'Copyright (c) .NET Foundation and contributors. All rights reserved.'

# Description of the functionality provided by this module
# Description = ''

# Minimum version of the PowerShell engine required by this module
PowerShellVersion = '7.0.0'

# 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 = @()

# 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 = @('Microsoft', '.NET', 'Jupyter', 'dotnet')

# A URL to the license for this module.
LicenseUri = 'https://github.com/dotnet/interactive/blob/master/License.txt'

# A URL to the main website for this project.
ProjectUri = 'https://github.com/dotnet/interactive'

# A URL to an icon representing this module.
# IconUri = ''

# ReleaseNotes of this module
ReleaseNotes = '# v0.1.0

Initial release.
'

# Prerelease string of this module
# Prerelease = ''
} # 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 = ''

}
81 changes: 81 additions & 0 deletions Microsoft.DotNet.Interactive.PowerShell/PowerShellExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// 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;
using System.Threading.Tasks;

namespace Microsoft.DotNet.Interactive.PowerShell
{
using System.Management.Automation;
Comment thread
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 async Task InvokeAndClearCommandsAsync(this PowerShell pwsh)
{
try
{
await pwsh.InvokeAsync().ConfigureAwait(false);
}
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();
}
}
}
}
Loading