Skip to content

Commit 2f8f30a

Browse files
adityapatwardhanTravisEz13
authored andcommitted
Add scripts to generate unified Nuget package (#6167)
Remove the functions which generated Nuget packages for Windows. Add function New-UnifiedNugetPackage to generate nuget packages for each assembly with unix and windows runtimes. Add function New-NuSpec and New-ReferenceAssembly for creating the required items forNew-UnifiedNugetPackage. Add a sample for cross platform project with conditional compilation for Linux. Add function Publish-NugetToMyGet to publish nuget packages to powershell.myget.or # Conflicts: # tools/packaging/packaging.psm1
1 parent baaf422 commit 2f8f30a

9 files changed

Lines changed: 684 additions & 18 deletions

File tree

.spelling

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ writingpestertests.md
206206
WSMan
207207
wsmansessionoption.cs
208208
xUnit
209+
0-powershell-crossplatform
209210
#endregion
210211

211212
#region ./tools/install-powershell.readme.md Overrides

docs/host-powershell/README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Host PowerShell Core in .NET Core Applications
22

3+
## PowerShell Core v6.0.1 and Later
4+
5+
The runtime assemblies for Windows, Linux and OSX are now published in NuGet package version 6.0.1.1 and above.
6+
7+
Please see the [.NET Core Sample Application](#net-core-sample-application) section for an example that uses PowerShell Core `6.0.1.1` NuGet packages.
8+
39
## PowerShell Core v6.0.0-beta.3 and Later
410

511
PowerShell Core is refactored in v6.0.0-beta.3 to remove the dependency on a customized `AssemblyLoadContext`.
@@ -138,6 +144,7 @@ namespace Application.Test
138144
.NET Core SDK `2.0.0-preview1-005952` or higher is required.
139145
- [sample-dotnet2.0-powershell.beta.3](./sample-dotnet2.0-powershell.beta.3) - .NET Core `2.0.0` + PowerShell Core `beta.3` NuGet packages.
140146
.NET Core SDK `2.0.0-preview1-005952` or higher is required.
147+
- [sample-dotnet2.0-powershell-crossplatform](./sample-dotnet2.0-powershell-crossplatform) - .Net Core `2.0.0` + PowerShell Core `6.0.1.1` NuGet packages.
141148

142149
You can find the sample application project `"MyApp"` in each of the above 3 sample folders.
143150
To build the sample project, run the following commands (make sure the required .NET Core SDK is in use):
@@ -147,6 +154,9 @@ dotnet restore .\MyApp\MyApp.csproj
147154
dotnet publish .\MyApp -c release -r win10-x64
148155
```
149156

157+
For cross platform project there is no need to specify `-r win10-x64`.
158+
The runtime for the build machine's platform will automatically be selected.
159+
150160
Then you can run `MyApp.exe` from the publish folder and see the results:
151161

152162
```none
@@ -161,9 +171,3 @@ Evaluating '([S.M.A.ActionPreference], [S.M.A.AliasAttribute]).FullName' in PS C
161171
System.Management.Automation.ActionPreference
162172
System.Management.Automation.AliasAttribute
163173
```
164-
165-
## Remaining Issue
166-
167-
PowerShell Core builds separately for Windows and Unix, so the assemblies are different between Windows and Unix platforms.
168-
Unfortunately, all PowerShell NuGet packages that have been published so far only contain PowerShell assemblies built specifically for Windows.
169-
The issue [#3417](https://github.com/PowerShell/PowerShell/issues/3417) was opened to track publishing PowerShell NuGet packages for Unix platforms.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp2.0</TargetFramework>
5+
<AssemblyName>MyApp</AssemblyName>
6+
<OutputType>Exe</OutputType>
7+
<RuntimeIdentifiers>win10-x64;linux-x64;osx.10.12-x64</RuntimeIdentifiers>
8+
</PropertyGroup>
9+
10+
<ItemGroup>
11+
<PackageReference Include="Microsoft.PowerShell.SDK" Version="6.0.1.1" />
12+
</ItemGroup>
13+
</Project>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
using System;
5+
using System.Management.Automation;
6+
7+
namespace Application.Test
8+
{
9+
public class Program
10+
{
11+
/// <summary>
12+
/// Managed entry point shim, which starts the actual program
13+
/// </summary>
14+
public static int Main(string[] args)
15+
{
16+
using (PowerShell ps = PowerShell.Create())
17+
{
18+
Console.WriteLine("\nEvaluating 'Get-Command Write-Output' in PS Core Runspace\n");
19+
var results = ps.AddScript("Get-Command Write-Output").Invoke();
20+
Console.WriteLine(results[0].ToString());
21+
}
22+
return 0;
23+
}
24+
}
25+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<packageSources>
4+
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
5+
<add key="dotnet-core" value="https://dotnet.myget.org/F/dotnet-core/api/v3/index.json" />
6+
<add key="powershell-core" value="https://powershell.myget.org/F/powershell-core/api/v3/index.json" />
7+
</packageSources>
8+
</configuration>

docs/maintainers/releasing.md

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -173,16 +173,9 @@ Start-PSPackage -Type zip -ReleaseTag v6.0.0-beta.1 -WindowsRuntime 'win7-x64'
173173

174174
## NuGet Packages
175175

176-
In the `release` branch, run `Publish-NuGetFeed` to generate PowerShell NuGet packages:
177-
178-
```powershell
179-
# Assume the to-be-used release tag is 'v6.0.0-beta.1'
180-
Publish-NuGetFeed -ReleaseTag 'v6.0.0-beta.1'
181-
```
182-
183-
PowerShell NuGet packages and the corresponding symbol packages will be generated at `PowerShell/nuget-artifacts` by default.
184-
Currently the NuGet packages published to [powershell-core feed][ps-core-feed] only contain assemblies built for Windows.
185-
Maintainers are working on including the assemblies built for non-Windows platforms.
176+
The NuGet packages for hosting PowerShell for Windows and non-Windows are being built in our release build pipeline.
177+
The assemblies from the individual Windows and Linux builds are consumed and packed into NuGet packages.
178+
These are then released to [powershell-core feed][ps-core-feed].
186179

187180
[ps-core-feed]: https://powershell.myget.org/gallery/powershell-core
188181

tools/packaging/packaging.psd1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ CompanyName="Microsoft Corporation"
55
Copyright="Copyright (c) Microsoft Corporation. All rights reserved."
66
ModuleVersion="1.0.0"
77
PowerShellVersion="5.0"
8-
CmdletsToExport=@("Start-PSPackage",'New-PSSignedBuildZip')
8+
CmdletsToExport=@("Start-PSPackage",'New-PSSignedBuildZip', 'New-UnifiedNugetPackage')
99
RootModule="packaging.psm1"
1010
RequiredModules = @("build")
1111
}

0 commit comments

Comments
 (0)