Powershell: Package 'PowerShell 6.2.2' has a package type 'DotnetTool' that is not supported by project 'myProject'.

Created on 19 Aug 2019  路  4Comments  路  Source: PowerShell/PowerShell

Hi!
I have a recently created C# win forms application using .Net Framework 4.7.2.
When I try to install Powershell NuGet I get the following error
"Package 'PowerShell 6.2.2' has a package type 'DotnetTool' that is not supported by project 'myProject'."

Nothing added to this project yet (no other NuGets, libraries, etc...)

Issue-Question Resolution-Answered

All 4 comments

PowerShell 6.2.2 isn't supported under .NET Framework -- it's built, tested, and runs on .NET Core 2.x; you cannot use PowerShell versions 6.x and above with .NET Framework, to my understanding. 馃檪

@johnykes the package you're linking to is the PowerShell dotnet global tool, which isn't designed for use in projects -- it's a global tool for the dotnet CLI (unfortunately they require a NuGet package like this to consume).

If you're targeting only Windows PowerShell (version 5.1) you might be looking for https://www.nuget.org/packages/Microsoft.PowerShell.5.ReferenceAssemblies/.

If you're building a module or something else to be loaded/run from PowerShell, then you might want to target https://www.nuget.org/packages/PowerShellStandard.Library/ for compatibility with both PowerShell 5.1 and PowerShell 7. You'll need to retarget your application to .NET Standard 2.0 (netstandard2.0).

If you're building an application that hosts PowerShell and want it to be compatible with both Windows PowerShell 5.1 and PowerShell 7, you'll want something like this in your csproj:

<PropertyGroup>
    <!-- all the other stuff needed -->
    <TargetFrameworks>net472;netcoreapp3.0</TargetFrameworks>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'net472'">
    <PackageReference Include="Microsoft.PowerShell.5.ReferenceAssemblies" Version="1.1.0" />
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'netcoreapp3.0'">
    <PackageReference Include="Microsoft.PowerShell.SDK" Version="7.0.0-preview.2" />
</PropertyGroup>

That will then allow conditional compilation in the code:

#if NET472
    // Windows PowerShell code
#else
    // PowerShell 7 code
#endif

In that scenario, because you have two targets, you would produce two sets of binaries.

Note that because you are writing a WinForms application, it won't work in PowerShell 6.x, only PowerShell 7+.

I have another project c# win forms application using .NET Framework 4.6.1 and NuGet "PowerShell" by Nasim
image
I can't find anymore this NuGet (by Nasim)
I tried your solutions but I can't use these NuGets in the same way, like below:

//Create a powershell terminal
PowerShell.RunPowerShell PS = new PowerShell.RunPowerShell();

//Set powershell script
string psCommand = "$s = New-PSSession -ComputerName " + server... blah blah

//Run powershell script
string output = PS.InvokePS(psCommand);

But using https://www.nuget.org/packages/Microsoft.PowerShell.5.ReferenceAssemblies/
I can use powershell like in the stackoverflow example
https://stackoverflow.com/questions/19601043/how-do-i-run-powershell-command-in-windows-form-application

Thanks!

Contains the SDK reference assemblies for PowerShell version 5
Stack Overflow
I am currently trying to implement the below ps command in my c# forms app. Im using Quest Powershell cmdlet Add-PSSnapin -Name Quest.ActiveRoles.ADManagement get-qadmemberof -identity ...
Was this page helpful?
0 / 5 - 0 ratings