mirror of
https://github.com/aphrody-labs/PowerShell.git
synced 2026-10-17 12:45:47 +00:00
Merge pull request #1075 from PowerShell/andschwa/binary-compatibility
Cross-platform (FullCLR/CoreCLR) binary module creation
This commit is contained in:
commit
06f563bb07
4 files changed
+23
-8
No files matched your search
@@ -59,6 +59,11 @@ test_script:
|
||||
{
|
||||
throw "$($x.'test-results'.failures) tests in test/fullCLR failed"
|
||||
}
|
||||
#
|
||||
# Portable module test
|
||||
Write-Host -Foreground Green 'Test use of cross-platform binary module'
|
||||
Import-Module ./docs/cmdlet-example/bin/Debug/netstandard1.3/SendGreeting.dll
|
||||
Send-Greeting -Name World
|
||||
|
||||
|
||||
on_finish:
|
||||
|
||||
@@ -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
|
||||
```
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
},
|
||||
|
||||
"frameworks": {
|
||||
"netstandard1.5": {
|
||||
"netstandard1.3": {
|
||||
"imports": [ "net40" ],
|
||||
"dependencies": {
|
||||
"Microsoft.NETCore": "5.0.1-rc2-24103",
|
||||
|
||||
Reference in new issue
Block a user