You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have an assembly-based power shell module (pshosts) that I'd like to port to ps-core.
Obviously my first steps are going to be compiling the assembly for .net core, but I'm at a loss for what needs to be done for the module declaration. For example, does ps-core define any additional psm1 syntax for specifying supported platforms or having separate assemblies for full vs core clrs?
I realise its early days right now, but any help would be appreciated.
as of PS 5.1 (avail in win10 & will be in Server 2016) there is an additional property available in the PowerShell Module Manifests called CompatiblePSEditions
This currently supports Desktop & Core as the possible options and I believe that the PSScriptAnalyzer has been updated to be able to scan for this.
However
As soon as you add that the module is unable to be installed on downlevel PS versions like PSv2 - PSv5 (currently)
I know this is something that myself and other MVP's have been discussing in the last few days.
But I would be doing what you are suggesting and trying to recompile for .NET core anyway as that should still run on .NET Full versions (note should because I'm not 100% on that)
Hrm, dropping support for PSv3-5 would be a deal breaker for me, I think, especially since I already distribute via the psgallery so I wouldn't be able to split it via distribution channel. Are there any plans for that to change? (you did say "currently")
Still, in the meantime I'll look at getting it working under pscore so I'm ready when things change (or those versions become irrelevant - if you know anyone on the psgallery side of things, tell them that OS/PSversion download statistics would be handy :)
Obviously PSEdition = Core is not required to get the module to load, and cannot be used without breaking backwards compatibility anyway.
The problem
You need to ship one module because the PowerShellGallery doesn't currently handle having multiple architecture-specific versions of assemblies.
You need to load the right assembly at run time
Solution Ideas
Fix it at install time: Fix the PowerShellGallery and the module to be able to publish multiple modules based on the PSEdition and/or PSVersion, and download the right version automatically, or the specified version on demand, or all versions.
Fix it at load time: Decide on a convention (probably just use the same convention that NuGet uses right?) and make Add-Type -Assembly and RequiredAssembliesand alsoRootModule to load the right assembly automatically.
I tried to port one of my assembly based ps modules to ps core on Linux and managed to make it work. I have the same issue as Richard Szalay (@richardszalay) pointed out on how to publish the module to the psgallery so I would as well appreciate any suggestion.
If I can add to the conversation a secondary issue I experienced is that when I build the module (dll) in the dotnet core project, the nuget dependencies are not copied to the output folder. My understanding is that this is by dotnet core design, and there is no way around it. Dependencies are only copied to the output directory when publishing a command line executable. So, just for the sake of testing, I copied the dependencies manually. Some of the dependencies were actually not required (like all the System.* that are already loaded by the powershell assembly), so I also add to remove the redundant dependencies. This makes the task of packaging the resource quite painful.
It would be nice if somehow the dependencies could be installed directly from nuget when installing the package. Maybe adding the dependency list on the module manifest.
Any updates on this? I've seen .NetCore module suffix from the Azure and AWS teams. Google Cloud doesn't publish to the PS Gallery so they simply provide a separate download.
I'd be happy if that were the guidance, but I'd also be happy with any official guidance.
(as a reminder, this is the scenario where I'd like to retain compatibility with PowerShell 3 while also supporting PsCore)
For what it's worth, a binary module can be constructed now targeting .Net Standard 1.6 that will work just fine in full Windows PowerShell with Full Framework as well as PowerShell Core. If you don't need to add functionality per OS, there shouldn't be any need to do anything tricky.
Activity
kilasuit commentedon Aug 18, 2016
as of PS 5.1 (avail in win10 & will be in Server 2016) there is an additional property available in the PowerShell Module Manifests called CompatiblePSEditions
This currently supports Desktop & Core as the possible options and I believe that the PSScriptAnalyzer has been updated to be able to scan for this.
However
As soon as you add that the module is unable to be installed on downlevel PS versions like PSv2 - PSv5 (currently)
I know this is something that myself and other MVP's have been discussing in the last few days.
But I would be doing what you are suggesting and trying to recompile for .NET core anyway as that should still run on .NET Full versions (note should because I'm not 100% on that)
richardszalay commentedon Aug 18, 2016
Hrm, dropping support for PSv3-5 would be a deal breaker for me, I think, especially since I already distribute via the psgallery so I wouldn't be able to split it via distribution channel. Are there any plans for that to change? (you did say "currently")
Still, in the meantime I'll look at getting it working under pscore so I'm ready when things change (or those versions become irrelevant - if you know anyone on the psgallery side of things, tell them that OS/PSversion download statistics would be handy :)
kilasuit commentedon Aug 18, 2016
I'd need to dig out some notes but yes this as it is currently. Plans around how this works going forward are still tbd I believe
richardszalay commentedon Aug 19, 2016
No problems, at least I'll be prepared.
Jaykul commentedon Aug 20, 2016
Isn't this as good a place as anywhere to discuss this? Ryan Yates (@kilasuit), Kirk Munro (@KirkMunro) Keith Hill (@rkeithhill)
Obviously
PSEdition = Coreis not required to get the module to load, and cannot be used without breaking backwards compatibility anyway.The problem
Solution Ideas
Add-Type -AssemblyandRequiredAssembliesand alsoRootModuleto load the right assembly automatically.gigi81 commentedon Aug 20, 2016
I tried to port one of my assembly based ps modules to ps core on Linux and managed to make it work. I have the same issue as Richard Szalay (@richardszalay) pointed out on how to publish the module to the psgallery so I would as well appreciate any suggestion.
If I can add to the conversation a secondary issue I experienced is that when I build the module (dll) in the dotnet core project, the nuget dependencies are not copied to the output folder. My understanding is that this is by dotnet core design, and there is no way around it. Dependencies are only copied to the output directory when publishing a command line executable. So, just for the sake of testing, I copied the dependencies manually. Some of the dependencies were actually not required (like all the System.* that are already loaded by the powershell assembly), so I also add to remove the redundant dependencies. This makes the task of packaging the resource quite painful.
It would be nice if somehow the dependencies could be installed directly from nuget when installing the package. Maybe adding the dependency list on the module manifest.
richardszalay commentedon Dec 3, 2016
Any updates on this? I've seen
.NetCoremodule suffix from the Azure and AWS teams. Google Cloud doesn't publish to the PS Gallery so they simply provide a separate download.I'd be happy if that were the guidance, but I'd also be happy with any official guidance.
(as a reminder, this is the scenario where I'd like to retain compatibility with PowerShell 3 while also supporting PsCore)
richardszalay commentedon Dec 4, 2016
... or is this one of those things that will be a non-issue with netcore 2.0?
Jaykul commentedon Jan 14, 2017
For what it's worth, a binary module can be constructed now targeting .Net Standard 1.6 that will work just fine in full Windows PowerShell with Full Framework as well as PowerShell Core. If you don't need to add functionality per OS, there shouldn't be any need to do anything tricky.
richardszalay commentedon Jan 14, 2017
Thanks Jaykul,
Does this apply to a specific version of PSCore?
Also does this mean no longer having to make a change to the manifest (thereby losing support for PS < 5) to support PSCore?
SteveL-MSFT commentedon Mar 6, 2017
Richard Szalay (@richardszalay) this PR #3095 has documentation on producing portable modules that work on both Windows PowerShell and PowerShell Core
SteveL-MSFT commentedon Mar 28, 2019
We've published some documentation on this so I believe we can consider this closed:
https://docs.microsoft.com/en-us/powershell/scripting/learn/writing-portable-modules?view=powershell-6
also see
https://devblogs.microsoft.com/powershell/powershell-standard-library-build-single-module-that-works-across-windows-powershell-and-powershell-core/