mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
update the doc about hosting powershell with a sample that uses beta.1 packages (#3770)
This commit is contained in:
@@ -832,4 +832,7 @@ CorePsAssemblyLoadContext.cs
|
||||
sample-dotnet1
|
||||
NTLM-based
|
||||
Kerberos-based
|
||||
preview1-002106-00
|
||||
sample-dotnet2
|
||||
0-powershell
|
||||
post-6
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
> This documentation is based on PowerShell Core packages built against .NET Core 1.1 and prior.
|
||||
> Things may change after we move to .NET Core 2.0.
|
||||
>
|
||||
> **Note** PowerShell v6.0.0-beta.1 has been released, which is on top of .NET Core 2.0 ([preview1-002106-00][netcoreapp20-preview1]).
|
||||
> The existing design of `PowerShell AssemblyLoadContext` is not changed in `beta.1` release,
|
||||
> so the way to host PowerShell `beta.1` is the same as before from the C# code perspective.
|
||||
> However, you will need the 2.0 preview version of .NET Core SDK <sub>(the version `2.0.0-preview1-005952` is currently used to build PowerShell Core)</sub>,
|
||||
> and the `.csproj` file will need to be updated.
|
||||
> A .NET Core 2.0 version of the sample application project `"MyApp"` can be found under [sample-dotnet2.0-powershell.beta.1](./sample-dotnet2.0-powershell.beta.1) for your reference.
|
||||
|
||||
## PowerShell Core targeting .NET Core 1.1 and Prior
|
||||
|
||||
@@ -153,6 +160,7 @@ PowerShell Core builds separately for Windows and Unix, so the assemblies are di
|
||||
Unfortunately, all PowerShell NuGet packages that have been published so far only contain PowerShell assemblies built specifically for Windows.
|
||||
The issue [#3417](https://github.com/PowerShell/PowerShell/issues/3417) was opened to track publishing PowerShell NuGet packages for Unix platforms.
|
||||
|
||||
[netcoreapp20-preview1]: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.NETCore.App/2.0.0-preview1-002106-00
|
||||
[CorePsAssemblyLoadContext.cs]: https://github.com/PowerShell/PowerShell/blob/master/src/Microsoft.PowerShell.CoreCLR.AssemblyLoadContext/CoreCLR/CorePsAssemblyLoadContext.cs
|
||||
[Resolving]: https://github.com/dotnet/corefx/blob/ec2a6190efa743ab600317f44d757433e44e859b/src/System.Runtime.Loader/ref/System.Runtime.Loader.cs#L35
|
||||
[bootstrapping]: https://github.com/PowerShell/PowerShell/blob/master/src/powershell/Program.cs#L27
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<AssemblyName>Logic</AssemblyName>
|
||||
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.0-beta.1" />
|
||||
<PackageReference Include="Microsoft.PowerShell.Commands.Diagnostics" Version="6.0.0-beta.1" />
|
||||
<PackageReference Include="Microsoft.WSMan.Management" Version="6.0.0-beta.1"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,35 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
using System;
|
||||
using System.Management.Automation;
|
||||
using System.Management.Automation.Runspaces;
|
||||
|
||||
namespace Application.Test
|
||||
{
|
||||
public sealed class Logic
|
||||
{
|
||||
/// <summary>
|
||||
/// Start the actual logic
|
||||
/// </summary>
|
||||
public static int Start(string[] args)
|
||||
{
|
||||
using (PowerShell ps = PowerShell.Create())
|
||||
{
|
||||
Console.WriteLine("\nEvaluating 'Get-Command Write-Output' in PS Core Runspace\n");
|
||||
var results = ps.AddScript("Get-Command Write-Output").Invoke();
|
||||
Console.WriteLine(results[0].ToString());
|
||||
|
||||
ps.Commands.Clear();
|
||||
|
||||
Console.WriteLine("\nEvaluating '([S.M.A.ActionPreference], [S.M.A.AliasAttribute]).FullName' in PS Core Runspace\n");
|
||||
results = ps.AddScript("([System.Management.Automation.ActionPreference], [System.Management.Automation.AliasAttribute]).FullName").Invoke();
|
||||
foreach (dynamic result in results)
|
||||
{
|
||||
Console.WriteLine(result.ToString());
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<AssemblyName>MyApp</AssemblyName>
|
||||
<OutputType>Exe</OutputType>
|
||||
<RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Logic\Logic.csproj" />
|
||||
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.0-beta.1" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,32 @@
|
||||
/********************************************************************++
|
||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
--********************************************************************/
|
||||
|
||||
using System.Management.Automation;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Application.Test
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// Managed entry point shim, which starts the actual program
|
||||
/// </summary>
|
||||
public static int Main(string[] args)
|
||||
{
|
||||
// Application needs to use PowerShell AssemblyLoadContext if it needs to create powershell runspace
|
||||
// PowerShell engine depends on PS ALC to provide the necessary assembly loading/searching support that is missing from .NET Core
|
||||
string appBase = System.IO.Path.GetDirectoryName(typeof(Program).GetTypeInfo().Assembly.Location);
|
||||
System.Console.WriteLine("\nappBase: {0}", appBase);
|
||||
|
||||
// Initialize the PS ALC and let it load 'Logic.dll' and start the execution
|
||||
return (int)PowerShellAssemblyLoadContextInitializer.
|
||||
InitializeAndCallEntryMethod(
|
||||
appBase,
|
||||
new AssemblyName("Logic, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"),
|
||||
"Application.Test.Logic",
|
||||
"Start",
|
||||
new object[] { args });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<configuration>
|
||||
<packageSources>
|
||||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
|
||||
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
|
||||
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
|
||||
</packageSources>
|
||||
</configuration>
|
||||
Reference in New Issue
Block a user