Skip to content

Commit b69d5e6

Browse files
authored
release 5.1.1 - which adds an assembly for net452 (PowerShell#60)
* Update to build both net452 and netstandard2.0 assemblies Update build script to allow building only core Update nuspec file to include both 452 and netstandard2.0 assemblies * Fix location of demo assemble for full clr test * Update template to use GA release Update signing.xml to use GA release. * install framework 4.5.2 now that we're building both netstandard2.0 and net452 * Trying something different, we'll not install the devpack, but install VS2017 * Remote install of vs2017, try installing runtime and devpack for 4.7.2 * pull proper image for building * Add tests to be sure the signing file reflects the actual files update the template package version * Add usage language to readme * remove unused screen shots * Changes for release 5.1.1
1 parent 367fdc1 commit b69d5e6

25 files changed

+509
-30
lines changed

Images/CopyLocal.png

17.3 KB
Loading

PowerShellStandard.psm1

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,18 @@
11
function Start-Build {
2+
param ( [switch]$CoreOnly )
23
$versions = 3,5
34
$srcBase = Join-Path $PsScriptRoot src
45
foreach ( $version in $versions ) {
56
try {
67
$srcDir = Join-Path $srcBase $version
78
Push-Location $srcDir
89
dotnet restore
9-
dotnet build --configuration Release
10+
if ( $CoreOnly ) {
11+
dotnet build --configuration Release --framework netstandard2.0
12+
}
13+
else {
14+
dotnet build --configuration Release
15+
}
1016
}
1117
finally {
1218
Pop-Location
@@ -49,13 +55,40 @@ function Start-Clean {
4955
}
5056

5157
function Invoke-Test {
58+
param ( [switch]$CoreOnly )
59+
# first, run the package tests and validate that the signing.xml file is correct
60+
try {
61+
$testBase = Join-Path $PsScriptRoot test
62+
Push-Location $testBase
63+
Invoke-Pester -Path ./Build.Tests.ps1
64+
}
65+
finally {
66+
Pop-Location
67+
}
5268
$versions = 3,5
5369
foreach ( $version in $versions ) {
5470
try {
5571
$testBase = Join-Path $PsScriptRoot "test/${version}"
5672
Push-Location $testBase
57-
dotnet build --configuration Release
58-
Invoke-Pester
73+
foreach ( $framework in "core","full" ) {
74+
if ( $CoreOnly -and $framework -eq "full" ) {
75+
continue
76+
}
77+
try {
78+
Push-Location $framework
79+
if ( $CoreOnly ) {
80+
dotnet build --configuration Release --framework netstandard2.0
81+
Invoke-Pester
82+
}
83+
else {
84+
dotnet build --configuration Release
85+
Invoke-Pester
86+
}
87+
}
88+
finally {
89+
pop-location
90+
}
91+
}
5992
}
6093
finally {
6194
Pop-Location

README.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,92 @@ To remove all build artifacts (except for the .nuget files in the root of the re
6565
```powershell
6666
./build.ps1 -Clean
6767
```
68+
69+
## How to use the PowerShell Standard Library
70+
71+
### Via Visual Studio
72+
73+
Using the PowerShell Standard Library within Visual Studio is as simple as installing the package into your solution and building the project
74+
75+
Create a project, and in the Package Manager Console (Tools -> Nuget Package Manager -> Package Manager Console) type:
76+
77+
```powershell
78+
install-package -id PowerShellStandard.Library
79+
```
80+
81+
This will add `System.Management.Automation` to your project references.
82+
After this, you must set `Copy Local` to False in the Reference Properties pane.
83+
84+
![Copy Local = False](Images/CopyLocal.png)
85+
86+
This will keep the PowerShell Standard Library from being copied into your release/publish directories.
87+
This is because the PowerShell Standard Library is a _reference_ assembly and doesn't actually contain any implementations and should never be distributed with your module.
88+
You may now create and build your module in the usual way.
89+
90+
Once your module is built, you can see the portability of your module very easily, if you have both Windows PowerShell and PowerShell core on your system.
91+
The following demonstrates the portability of using PowerShell Standard.
92+
93+
The following shows the same assembly being used by both Windows PowerShell, PowerShell Core, and via Docker; PowerShell Core on Linux.
94+
95+
```powershell
96+
PS> powershell
97+
Windows PowerShell
98+
Copyright (C) Microsoft Corporation. All rights reserved.
99+
100+
Loading personal and system profiles took 714ms.
101+
PS> gci
102+
103+
Directory: C:\users\jimtru\documents\visual studio 2017\Projects\ClassLibrary2\ClassLibrary2\bin\Debug
104+
105+
Mode LastWriteTime Length Name
106+
---- ------------- ------ ----
107+
-a---- 3/7/2019 10:54 AM 4608 ClassLibrary2.dll
108+
-a---- 3/7/2019 10:54 AM 15872 ClassLibrary2.pdb
109+
110+
PS> import-module .\ClassLibrary2.dll
111+
PS> "joe","jane" | Invoke-Demo
112+
Hello 'joe'
113+
Hello 'jane'
114+
PS> exit
115+
116+
PS> pwsh-preview
117+
PowerShell 6.1.0-rc.1
118+
Copyright (c) Microsoft Corporation. All rights reserved.
119+
120+
https://aka.ms/pscore6-docs
121+
Type 'help' to get help.
122+
123+
PS> import-module .\ClassLibrary2.dll
124+
PS> "joe","jane" | Invoke-Demo
125+
Hello 'joe'
126+
Hello 'jane'
127+
PS> exit
128+
129+
PS> $m = "C:\Users\jimtru\DOCUME~1\VIBB41~1\Projects\CLASSL~2\CLASSL~1\bin\Debug"
130+
PS> docker run --rm -it -v "${m}:/module" mcr.microsoft.com/powershell:preview
131+
PowerShell 6.2.0-rc.1
132+
Copyright (c) Microsoft Corporation. All rights reserved.
133+
134+
https://aka.ms/pscore6-docs
135+
Type 'help' to get help.
136+
137+
PS /> hostname
138+
add7d6ed4818
139+
140+
PS /> select-string pretty /etc/os-release
141+
etc/os-release:5:PRETTY_NAME="Ubuntu 18.04.2 LTS"
142+
143+
PS /> gci /module
144+
Directory: /module
145+
Mode LastWriteTime Length Name
146+
---- ------------- ------ ----
147+
------ 3/7/19 6:54 PM 4608 ClassLibrary2.dll
148+
------ 3/7/19 6:54 PM 15872 ClassLibrary2.pdbPS /> import-module /module/ClassLibrary2.dll
149+
150+
PS /> Import-Module /module/ClassLibrary2.dll
151+
PS /> "joe","jane" | Invoke-Demo
152+
Hello 'joe'
153+
Hello 'jane'
154+
```
155+
156+
And that's how you can build a single module used by Windows PowerShell, PowerShell Core on Windows and Linux!

build.ps1

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
#!/usr/bin/env pwsh
22
param (
3-
[Parameter()][switch]$Clean,
4-
[Parameter()][switch]$Test,
5-
[Parameter()][switch]$Pack
3+
[Parameter(HelpMessage="Remove earlier built versions")][switch]$Clean,
4+
[Parameter(HelpMessage="Run the tests")][switch]$Test,
5+
[Parameter(HelpMessage="Create a .nupkg")][switch]$Pack,
6+
[Parameter(HelpMessage="Build only for netstandard2.0")][switch]$CoreOnly
67
)
78

89
import-module $PSScriptRoot/PowerShellStandard.psm1 -force
@@ -12,14 +13,25 @@ if ( $Clean ) {
1213
return
1314
}
1415

16+
# It would be great if there were targeting frameworks for net452
17+
# on non-Windows platforms, but for now, if you're linux or macOS
18+
# we'll build only core
19+
if ( $IsLinux -or $IsMacOS ) {
20+
$CoreOnly = $true
21+
}
22+
1523
if ( $Pack ) {
24+
if ( $CoreOnly ) {
25+
Write-Warning "Must build both netstandard2.0 and net452 to build package"
26+
throw "Build on a Windows system with netstandard and net452 target platforms"
27+
}
1628
Export-NuGetPackage
1729
}
1830
else {
19-
Start-Build
31+
Start-Build -CoreOnly:$CoreOnly
2032
}
2133

2234
if ( $Test ) {
23-
Invoke-Test
35+
Invoke-Test -CoreOnly:$CoreOnly
2436
}
2537

src/3/System.Management.Automation-lib.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2.0;net451</TargetFrameworks>
44
<SignAssembly>True</SignAssembly>
55
<AssemblyOriginatorKeyFile>..\signing\visualstudiopublic.snk</AssemblyOriginatorKeyFile>
66
<AssemblyName>System.Management.Automation</AssemblyName>
@@ -10,7 +10,7 @@
1010
<DefineConstants>RUNTIME_SERIALIZATION</DefineConstants>
1111
<NuspecFile>./PowershellStandard.Library.nuspec</NuspecFile>
1212
</PropertyGroup>
13-
<ItemGroup>
13+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'" >
1414
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />
1515
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
1616
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />

src/5/PowerShellStandard.Library.nuspec

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>PowerShellStandard.Library</id>
5-
<version>5.1.0-RC1</version>
5+
<version>5.1.1</version>
6+
<title>PowerShellStandard.Library</title>
67
<authors>Microsoft</authors>
78
<owners>Microsoft,PowerShellTeam</owners>
89
<projectUrl>https://github.com/PowerShell/PowerShellStandard</projectUrl>
@@ -11,13 +12,16 @@
1112
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1213
<description>Contains the reference assemblies for PowerShell Standard 5</description>
1314
<copyright>© Microsoft Corporation. All rights reserved.</copyright>
14-
<tags>PowerShell, reference, netstandard2, netstandard2.0</tags>
15+
<tags>PowerShell, reference, net452, netstandard2, netstandard2.0</tags>
1516
<references>
16-
<reference file="System.Management.Automation.dll" />
17+
<reference file="System.Management.Automation.dll" >
18+
<private>False</private>
19+
</reference>
1720
</references>
1821
</metadata>
1922
<files>
2023
<file src="obj/Release/netstandard2.0/System.Management.Automation.dll" target="lib/netstandard2.0" />
24+
<file src="obj/Release/net452/System.Management.Automation.dll" target="lib/net452" />
2125
</files>
2226
</package>
2327

src/5/System.Management.Automation-lib.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFramework>netstandard2.0</TargetFramework>
3+
<TargetFrameworks>netstandard2.0;net452</TargetFrameworks>
44
<SignAssembly>True</SignAssembly>
55
<AssemblyOriginatorKeyFile>..\signing\visualstudiopublic.snk</AssemblyOriginatorKeyFile>
66
<AssemblyName>System.Management.Automation</AssemblyName>
77
<AssemblyVersion>3.0.0</AssemblyVersion>
8-
<FileVersion>5.1.0</FileVersion>
8+
<FileVersion>5.1.1</FileVersion>
99
<DelaySign>True</DelaySign>
1010
<DefineConstants>RUNTIME_SERIALIZATION</DefineConstants>
1111
<NuspecFile>./PowershellStandard.Library.nuspec</NuspecFile>
1212
</PropertyGroup>
13-
<ItemGroup>
13+
<ItemGroup Condition="'$(TargetFramework)'=='netstandard2.0'" >
1414
<PackageReference Include="System.IO.FileSystem.AccessControl" Version="4.5.0" />
1515
<PackageReference Include="System.Security.AccessControl" Version="4.5.0" />
1616
<PackageReference Include="System.Security.Permissions" Version="4.5.0" />

src/dotnetTemplate/Microsoft.PowerShell.Standard.Module.Template/Microsoft.PowerShell.Standard.Module.Template.nuspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
33
<metadata>
44
<id>Microsoft.PowerShell.Standard.Module.Template</id>
5-
<version>0.1.3</version>
5+
<version>0.1.4</version>
66
<title>PowerShell Standard module</title>
77
<authors>Microsoft</authors>
88
<owners>Microsoft,PowerShellTeam</owners>

src/dotnetTemplate/Microsoft.PowerShell.Standard.Module.Template/Microsoft.PowerShell.Standard.Module.Template/Microsoft.PowerShell.Standard.Module.Template.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="PowerShellStandard.Library" Version="5.1.0-RC1">
9+
<PackageReference Include="PowerShellStandard.Library" Version="5.1.1">
1010
<PrivateAssets>All</PrivateAssets>
1111
</PackageReference>
1212

src/dotnetTemplate/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ PowerShell Standard Module (C#)
9595
Author: Microsoft Corporation
9696
Options:
9797
-v|--powershell-standard-version
98-
5.1.0-preview-03 - PowerShell Standard 5.1
98+
5.1.1 - PowerShell Standard 5.1.1
9999
3.0.0-preview-02 - PowerShell Standard 3.0
100-
Default: 5.1.0-preview-03
100+
Default: 5.1.1
101101
102102
--no-restore If specified, skips the automatic restore of the project on create.
103103
bool - Optional
@@ -132,4 +132,4 @@ This template will create:
132132

133133
* `*.csproj` - a project file that uses the same name as the folder it was created in
134134
* `TestSampleCmdletCommand.cs` - an example PowerShell cmdlet class
135-
* `obj` - a folder generated by the restore
135+
* `obj` - a folder generated by the restore
File renamed without changes.
File renamed without changes.

test/3/PSStandard.csproj renamed to test/3/core/PSStandard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<ProjectReference Include="../../src/3/System.Management.Automation-lib.csproj" />
9+
<ProjectReference Include="../../../src/3/System.Management.Automation-lib.csproj" />
1010
</ItemGroup>
1111

1212
</Project>

test/3/full/Class1.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Management.Automation;
3+
4+
namespace PSStandard
5+
{
6+
[Cmdlet("get","thing")]
7+
public class Class1 : PSCmdlet
8+
{
9+
[Parameter()]
10+
[Credential()]
11+
public PSCredential Credential { get; set; }
12+
13+
protected override void EndProcessing() {
14+
WriteObject("Success!");
15+
}
16+
}
17+
}

test/3/full/PSS3.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Describe "PowerShell Standard 3" {
2+
BeforeAll {
3+
$cmdletAssembly = "bin/Release/net452/Demo.Cmdlet.dll"
4+
$assemblyPath = Join-Path "$PSScriptRoot" $cmdletAssembly
5+
$PSBin = (Get-Process -id $PID).MainModule.FileName
6+
}
7+
It "Can build a reference assembly" {
8+
dotnet restore
9+
dotnet build --configuration Release
10+
$assemblyPath | Should Exist
11+
}
12+
It "Can execute the compiled cmdlet" {
13+
$result = & $PSBin -c "import-module $assemblyPath; Get-Thing"
14+
$result | Should Be "success!"
15+
}
16+
}

test/3/full/PSStandard.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net452</TargetFramework>
5+
<AssemblyName>Demo.Cmdlet</AssemblyName>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="../../../src/3/System.Management.Automation-lib.csproj" />
10+
</ItemGroup>
11+
12+
</Project>
File renamed without changes.
File renamed without changes.

test/5/PSStandard.csproj renamed to test/5/core/PSStandard.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<ProjectReference Include="../../src/5/System.Management.Automation-lib.csproj" />
9+
<ProjectReference Include="../../../src/5/System.Management.Automation-lib.csproj" />
1010
</ItemGroup>
1111

1212
</Project>

test/5/full/Class1.cs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
using System;
2+
using System.Management.Automation;
3+
using System.Management.Automation.Runspaces;
4+
5+
namespace PSStandard
6+
{
7+
[Cmdlet("get","thing")]
8+
public class Class1 : PSCmdlet
9+
{
10+
[Parameter()]
11+
[Credential()]
12+
public PSCredential Credential { get; set; }
13+
14+
[Parameter()]
15+
[ValidateSet("a","b","c")]
16+
public string p1 { get; set; }
17+
18+
protected override void BeginProcessing() {
19+
WriteVerbose(Runspace.DefaultRunspace.Name);
20+
PSObject p = new PSObject(DateTime.Now);
21+
WriteVerbose(p.Properties["DateTime"].ToString());
22+
}
23+
protected override void EndProcessing() {
24+
WriteObject("Success!");
25+
}
26+
}
27+
}

0 commit comments

Comments
 (0)