Wndrr Wndrr - 1 year ago 164
C# Question

Add PowerShell package to .netstandard2.0 class library

I'm trying to migrate a C# class library that I previously built which was targeting .NET Framework v4.5 to .NET Standard 2.0.

I tried many packages to include PowerShell support in my library but every time I include a package I get a warning saying that the package was included using a target framework different from the .NET Standard 2.0.

For example, with the System.Management.Automation_PowerShell_3.0` package I get the following error message


Le package 'System.Management.Automation_PowerShell_3.0 6.3.9600.17400' a été restauré en utilisant '.NETFramework,Version=v4.6.1' au lieu du framework cible du projet '.NETStandard,Version=v2.0'. Ce package n'est peut-être pas totalement compatible avec votre projet.


which would be roughly translated to English as


The package 'System.Management.Automation_PowerShell_3.0 6.3.9600.17400' was restored using '.NETFramework,Version=v4.6.1' instead of the projet's target framework '.NETStandard,Version=v2.0'. This package may not be completely compatible with the target project.


Since the main reason, I'm trying to port my library to .NET Standard is to support both the .NET Framework and the .NET Core targets, having a package one of the packages be .NET Framework-specific defeats the purpose of the port.

Do I have any workaround? Is there a PowerShell package that targets .NET Standard 2.0 that I missed (I tried about 10 PowerShell-related packaged in the VS17 NuGet explorer before posting here)?

For some background, I use PowerShell to run node.exe from my C# library.

Answer Source

As far as I know there isn't any way around this. The reason for that is the package is built using the .NETFramework so until the creators port their package to the .NETStandard, it will only be usable from .NETFramework apps since, in theory, that package could use libraries that are not in the .NETStandard.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download