Can I use PowerShell class in .Net Standard library to use in .Net Framework project (exe)


I am trying to create a .net standard 2.0 library that calls PowerShell commands and scripts using PowerShell classes (System.Management.Automation). I want to use this .Net Standard library in .Net Framework (4.7.2) project.

I have already tried using Microsoft.PowerShell.SDK and System.Management.Automation NuGet package in .Net Standard project but I keep getting this error:


 Message=Could not load file or assembly'System.Management.Automation, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Sample Code in .Net Standard 2.0 Library project:

Runspace runspace = RunspaceFactory.CreateRunspace();

PowerShell posh = PowerShell.Create();
posh.Runspace = runspace;

How can I achieve this? Any help is appreciated.

asked on Stack Overflow Jun 25, 2019 by Mark • edited Jun 25, 2019 by Mark

1 Answer


If you want to target .NET Standard, you should reference the PowerShellStandard.Library nuget package

PowerShell Standard exposes only the API surface that overlaps between PowerShell 5.1 (.NET Framework) and PowerShell Core (.NET Core), so it'll work regardless of which edition you compile against.

Recommended reading: PowerShell Standard Library: Build single module that works across Windows PowerShell and PowerShell Core

answered on Stack Overflow Jun 25, 2019 by Mathias R. Jessen

User contributions licensed under CC BY-SA 3.0