Powershell: Referencing System.Management.Automation in .NET Core / VS Code

Created on 16 Sep 2016  ·  3Comments  ·  Source: PowerShell/PowerShell

What's the correct way to reference System.Management.Automation? E.g., this snippet from project.json:

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.AspNetCore.Routing": "1.0.0",
    "System.Security.Cryptography.Algorithms": "4.2.0",
    "System.Management.Automation": "6.1.7601.17514"
  },

Works when you run dotnet restore in that it finds and claims to install the System.Management.Automation dependency (noting that .17515 isn't compatible with .NET Core). But you can't simply add a using in the code, or it says:

The type or namespace name 'Management' does not exist in the namespace 'System'

The intent here is to programmatically instantiate PowerShell in the code, but .NET Core is a bit restrictive in how it wants references handled...

Area-Maintainers-Build Issue-Question

All 3 comments

This is a known issue for NuGet that we are trying to resolve. There are a number of rogue System.Management.Automation packages that external people have posted. Those packages are all "FullCLR" assemblies and are not compatible with PowerShell Core.

The current way to consume the PowerShell Core version of System.Management.Automation is to copy the technique used by this project. Our nuget.config file points to the correct version that is posted to MyGet. powershell-win-core\project.json shows how to consume it within your project.json.

Hi Don.

There are few things about dotnet cli that may help you sort it out.

Perfect.

Was this page helpful?
0 / 5 - 0 ratings