0

Trying to add System.Management.Automation package to my project in visual studio because I want to run powershell commands through my code, but am getting the error:

The project does not support adding package references through the add package command. My dotnet --version is: 7.0.102

I inputted

dotnet add package System.Management.Automation --version 7.3.2

into the package manager console, and was expecting it to work as normal when adding a nuget package, however instead received the error

Error while adding package 'System.Management.Automation' to project 'C:\Users\userone\source\repos\blackjack21\blackjack21.csproj'. The project does not support adding package references through the add package command.

No idea what to do.

burnsi
  • 6,194
  • 13
  • 17
  • 27
leon
  • 1
  • 1
  • Powershell will work with .NET Standard 2.0 (take a look at the _Update_ to my answer to https://stackoverflow.com/questions/54834518/how-to-create-class-library-with-interfaces-and-or-methods-used-by-windows-and/54836589#54836589 - different, but probably relevant). If you are using .NET 7, you can reference a .NET Standard assembly. You will likely need to have an intermediate assembly to make everyone happy – Flydog57 Feb 07 '23 at 18:02
  • By the way, if you reduce your problem to a [mcve] (say a .NET 7 WinForms or Console app that runs a single PowerShell command), post your system configuration and your source, you will be much more likely to get an answer. As it is, someone needs to guess the details of your problem and then write code from scratch to come up with an answer (which will likely be somewhat off base). – Flydog57 Feb 07 '23 at 18:06
  • 1
    It sounds like maybe the project is a .NET Framework "non-sdk" style csproj. The `dotnet` CLI only works with "sdk-style" projects. If that's the case, you need to install the package in Visual Studio, either the Package Manager Console, or the package manager GUI (right click project, select manage nuget packages) – zivkan Feb 08 '23 at 10:21

0 Answers0