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
Copy file name to clipboardExpand all lines: reference/docs-conceptual/dev-cross-plat/Writing-Portable-Modules.md
+31-31Lines changed: 31 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,13 +1,13 @@
1
1
---
2
2
description: This article explains how to create modules new modules or update existing modules so that they work across the platforms supported by PowerShell.
3
-
ms.date: 11/16/2022
3
+
ms.date: 12/08/2025
4
4
title: Writing Portable Modules
5
5
---
6
6
7
7
# Portable Modules
8
8
9
-
Windows PowerShell is written for [.NET Framework][06] while PowerShell Core is written for
10
-
[.NET Core][03]. Portable modules are modules that work in both Windows PowerShell and PowerShell
9
+
Windows PowerShell is written for [.NET Framework][03] while PowerShell Core is written for
10
+
[.NET Core][04]. Portable modules are modules that work in both Windows PowerShell and PowerShell
11
11
Core. While .NET Framework and .NET Core are highly compatible, there are differences in the
12
12
available APIs between the two. There are also differences in the APIs available in Windows
13
13
PowerShell and PowerShell Core. Modules intended to be used in both environments need to be aware of
@@ -17,12 +17,12 @@ these differences.
17
17
18
18
### Porting a PSSnapIn
19
19
20
-
PowerShell [SnapIns][09] aren't supported in PowerShell Core. However, it's trivial to convert a
20
+
PowerShell [SnapIns][07] aren't supported in PowerShell Core. However, it's trivial to convert a
21
21
PSSnapIn to a PowerShell module. Typically, the PSSnapIn registration code is in a single source
22
-
file of a class that derives from [PSSnapIn][01]. Remove this source file from the build; it's no
22
+
file of a class that derives from [PSSnapIn][14]. Remove this source file from the build; it's no
23
23
longer needed.
24
24
25
-
Use [New-ModuleManifest][08] to create a new module manifest that replaces the need for the PSSnapIn
25
+
Use [New-ModuleManifest][13] to create a new module manifest that replaces the need for the PSSnapIn
26
26
registration code. Some values from the **PSSnapIn** (such as **Description**) can be reused within
27
27
the module manifest.
28
28
@@ -32,14 +32,14 @@ The **RootModule** property in the module manifest should be set to the name of
32
32
### The .NET Portability Analyzer (aka APIPort)
33
33
34
34
To port modules written for Windows PowerShell to work with PowerShell Core, start with the
35
-
[.NET Portability Analyzer][11]. Run this tool against your compiled assembly to determine if the
35
+
[.NET Portability Analyzer][08]. Run this tool against your compiled assembly to determine if the
36
36
.NET APIs used in the module are compatible with .NET Framework, .NET Core, and other .NET runtimes.
37
-
The tool suggests alternate APIs if they exist. Otherwise, you may need to add [runtime checks][02]
37
+
The tool suggests alternate APIs if they exist. Otherwise, you may need to add [runtime checks][15]
38
38
and restrict capabilities not available in specific runtimes.
39
39
40
40
## Creating a new module
41
41
42
-
If creating a new module, the recommendation is to use the [.NET CLI][05].
42
+
If creating a new module, the recommendation is to use the [.NET CLI][02].
43
43
44
44
### Installing the PowerShell Standard module template
45
45
@@ -143,15 +143,15 @@ FavoriteNumber FavoritePet
143
143
### Debugging the module
144
144
145
145
For a guide on setting up Visual Studio Code to debug the module, see
146
-
[Using Visual Studio Code for debugging compiled cmdlets][15].
146
+
[Using Visual Studio Code for debugging compiled cmdlets][12].
147
147
148
148
## Supporting technologies
149
149
150
150
The following sections describe in detail some of the technologies used by this template.
151
151
152
152
### .NET Standard Library
153
153
154
-
[.NET Standard][07] is a formal specification of .NET APIs that are available in all .NET
154
+
[.NET Standard][05] is a formal specification of .NET APIs that are available in all .NET
155
155
implementations. Managed code targeting .NET Standard works with the .NET Framework and .NET Core
156
156
versions that are compatible with that version of the .NET Standard.
157
157
@@ -173,10 +173,10 @@ PowerShell Core 6 without recompilation.
173
173
174
174
### PowerShell Standard Library
175
175
176
-
The [PowerShell Standard][12] library is a formal specification of PowerShell APIs available in all
176
+
The [PowerShell Standard][09] library is a formal specification of PowerShell APIs available in all
177
177
PowerShell versions greater than or equal to the version of that standard.
178
178
179
-
For example, [PowerShell Standard 5.1][13] is compatible with both Windows PowerShell 5.1 and
179
+
For example, [PowerShell Standard 5.1][10] is compatible with both Windows PowerShell 5.1 and
180
180
PowerShell Core 6.0 or newer.
181
181
182
182
We recommend you compile your module using PowerShell Standard Library. The library ensures the APIs
@@ -189,7 +189,7 @@ will always be compatible with future versions of PowerShell.
189
189
#### Indicating Compatibility With Windows PowerShell and PowerShell Core
190
190
191
191
After validating that your module works with both Windows PowerShell and PowerShell Core, the module
192
-
manifest should explicitly indicate compatibility by using the [CompatiblePSEditions][10] property.
192
+
manifest should explicitly indicate compatibility by using the [CompatiblePSEditions][06] property.
193
193
A value of `Desktop` means that the module is compatible with Windows PowerShell, while a value of
194
194
`Core` means that the module is compatible with PowerShell Core. Including both `Desktop` and `Core`
195
195
means that the module is compatible with both Windows PowerShell and PowerShell Core.
@@ -203,7 +203,7 @@ means that the module is compatible with both Windows PowerShell and PowerShell
203
203
204
204
First, validate that your module works on Linux and macOS. Next, indicate compatibility with those
205
205
operating systems in the module manifest. This makes it easier for users to find your module for
206
-
their operating system when published to the [PowerShell Gallery][14].
206
+
their operating system when published to the [PowerShell Gallery][11].
207
207
208
208
Within the module manifest, the `PrivateData` property has a `PSData` sub-property. The optional
209
209
`Tags` property of `PSData` takes an array of values that show up in PowerShell Gallery. The
@@ -272,7 +272,7 @@ Prior to PowerShell 7, one would have to have custom code to load the appropriat
272
272
the managed library can find it correctly.
273
273
274
274
With PowerShell 7, native binaries to load are searched in sub-folders within the managed library's
275
-
location following a subset of the [.NET RID Catalog][04] notation.
275
+
location following a subset of the [.NET RID Catalog][01] notation.
0 commit comments