From 1d96695a639d40bb4e5a7b54705328c335770085 Mon Sep 17 00:00:00 2001 From: Andrew Schwartzmeyer Date: Mon, 6 Jun 2016 11:28:44 -0700 Subject: [PATCH] Update cmdlet-example to use netstandard1.3 As this enables importing the same DLL everywhere. --- docs/cmdlet-example/README.md | 20 +++++++++++++++----- docs/cmdlet-example/SendGreeting.Tests.ps1 | 4 ++-- docs/cmdlet-example/project.json | 2 +- 3 files changed, 18 insertions(+), 8 deletions(-) diff --git a/docs/cmdlet-example/README.md b/docs/cmdlet-example/README.md index 0d56bb775..29cb6fa4e 100644 --- a/docs/cmdlet-example/README.md +++ b/docs/cmdlet-example/README.md @@ -2,7 +2,9 @@ Building a C# Cmdlet ==================== This example project demonstrates how to build your own C# cmdlet for -PowerShell. +PowerShell. When built in the following manner, the resulting DLL can be +imported everywhere: Windows PowerShell with Desktop .NET (FullCLR) and Open +PowerShell on Windows, Linux, and OS X with .NET Core (CoreCLR). Setup ----- @@ -24,7 +26,7 @@ least `1.0.0-rc2`. }, "frameworks": { - "netstandard1.5": { + "netstandard1.3": { "imports": [ "net40" ], "dependencies": { "Microsoft.NETCore": "5.0.1-*", @@ -49,8 +51,10 @@ Going through this step-by-step: - [Microsoft.PowerShell.5.ReferenceAssemblies][powershell]: Contains the SDK reference assemblies for PowerShell version 5. Targets the `net40` framework. -- [netstandard1.5][]: The target framework for .NET Core portable libraries. +- [netstandard1.3][]: The target framework for .NET Core portable libraries. This is an abstract framework that will work anywhere its dependencies work. + Specifically, the 1.3 version allows this assembly to work even on Windows + PowerShell with Desktop .NET. - `"imports": [ "net4" ]`: Since the PowerShell reference assemblies target the older `net40` framework, we `import` it here to tell `dotnet restore` that we @@ -83,7 +87,7 @@ this `NuGet.config` file to setup the [.NET Core MyGet feed][myget]: [dotnet-cli]: https://github.com/dotnet/cli#new-to-net-cli [powershell]: https://www.nuget.org/packages/Microsoft.PowerShell.5.ReferenceAssemblies -[netstandard1.5]: https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-standard-applications.md +[netstandard1.3]: https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-standard-applications.md [netcore]: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.NETCore [portable]: https://dotnet.myget.org/feed/dotnet-core/package/nuget/Microsoft.NETCore.Portable.Compatibility [myget]: https://dotnet.myget.org/gallery/dotnet-core @@ -108,7 +112,7 @@ Once packages are restored, building is simple: dotnet build ``` -This will produce the assembly `./bin/Debug/netstandard1.5/SendGreeting.dll`. +This will produce the assembly `./bin/Debug/netstandard1.3/SendGreeting.dll`. This build/restore process should work anywhere .NET Core works, including Windows, Linux, and OS X. @@ -127,3 +131,9 @@ Then import and use the module: > Send-Greeting -Name World Hello World! ``` + +You can also import by the path: + +```powershell +> Import-Module ./bin/Debug/netstandard1.3/SendGreeting.dll +``` diff --git a/docs/cmdlet-example/SendGreeting.Tests.ps1 b/docs/cmdlet-example/SendGreeting.Tests.ps1 index 1379cb60f..c4390fbe2 100644 --- a/docs/cmdlet-example/SendGreeting.Tests.ps1 +++ b/docs/cmdlet-example/SendGreeting.Tests.ps1 @@ -2,11 +2,11 @@ Describe "Send-Greeting cmdlet" -Tag 'Slow' { It "Should be able build the cmdlet" { Remove-Item -Recurse -Force bin -ErrorAction SilentlyContinue dotnet restore --verbosity Error | Should BeNullOrEmpty - dotnet build | ?{ $_ -match "Compiling SendGreeting for .NETStandard,Version=v1.5" } | Should Not BeNullOrEmpty + dotnet build | ?{ $_ -match "Compiling SendGreeting for .NETStandard,Version=v1.3" } | Should Not BeNullOrEmpty } It "Should be able to use the module" { - Import-Module -ErrorAction Stop ./bin/Debug/netstandard1.5/SendGreeting.dll + Import-Module -ErrorAction Stop ./bin/Debug/netstandard1.3/SendGreeting.dll Send-Greeting -Name World | Should Be "Hello World!" Remove-Module SendGreeting } diff --git a/docs/cmdlet-example/project.json b/docs/cmdlet-example/project.json index e176969da..a0556f329 100644 --- a/docs/cmdlet-example/project.json +++ b/docs/cmdlet-example/project.json @@ -8,7 +8,7 @@ }, "frameworks": { - "netstandard1.5": { + "netstandard1.3": { "imports": [ "net40" ], "dependencies": { "Microsoft.NETCore": "5.0.1-rc2-24103",