question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't resolve System.Management.Automation from GAC for net451 project

See original GitHub issue

I’m having trouble creating a desktop .NET 4.5.1 console application that references the PowerShell API DLL System.Management.Automation. When I set my frameworkAssemblies to refer to this DLL I get a compiler error. I also notice that Visual Studio’s completion results don’t contain this DLL:

image

What am I doing wrong?

Steps to reproduce

  1. Create a new console app project using dotnet new.
  2. Update project.json to the contents below
  3. Run dotnet restore
  4. Run dotnet compile

project.json

{
    "version": "1.0.0-*",
    "compilationOptions": {
        "emitEntryPoint": true
    },

    "frameworks": {
        "net451": {
          "frameworkAssemblies": {
            "System.Management.Automation": ""
          }
        }
    }
}

Expected behavior

Code compiles successfully, resolves System.Management.Automation.dll.

Actual behavior

Compile error:

PS> dotnet compile
Compiling dotnetrepro for .NETFramework,Version=v4.5.1
C:\dev\dotnetrepro\project.json(10,45): error NU1001: The dependency System.Management.Automation could not be resolved.

Compilation failed.
    0 Warning(s)
    1 Error(s)

Time elapsed 00:00:02.3045736

Environment data

dotnet --version output:

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.11082
 OS Platform: Windows
 Runtime Id:  win10-x64

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
daviwilcommented, Mar 14, 2016

I’m referring to the NuGet packages we released which contain reference assemblies (only metadata):

If you compile a .NET 4.5.x app against one of those NuGet packages then the PowerShell assemblies from the GAC will be loaded in your app at runtime. However, you’ll need to compile against the reference assemblies for the version of PowerShell used on the target machine otherwise you might get MissingMethodExceptions, etc. I’d recommend using the PowerShell 5 package if you’re targeting Windows 10 machines.

1reaction
Arnavioncommented, Mar 14, 2016

@daviwil I have the same question. What packages does “compiling against our official reference assembly packages” refer to? Presumably not the ancient ones that turn up in nuget when searching for “System.Management.Automation”…

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't resolve System.Management.Automation from GAC ...
I'm having trouble creating a desktop .NET 4.5.1 console application that references the PowerShell API DLL System.Management.Automation.
Read more >
Import-Module : Could not load file or assembly 'System. ...
I'm unable to run PnP PowerShell commands using PowerShell ISE in administrative mode. Getting following error PS C:\WINDOWS\system32> ...
Read more >
Cannot find reference for System.Management.Automation ...
1 Answer 1 ... For downloading Microsoft.PowerShell.5.ReferenceAssemblies in visual studio, you could try this download method (right click on the ...
Read more >
Downloading and Installing WinSCP .NET Assembly
NET assembly is available in a package named WinSCP-X.X.X-Automation.zip on WinSCP download page. Follow the .NET assembly/COM library link.
Read more >
Pro NuGet
NuGet, in essence, is a Visual Studio extension that comes bundled with Visual Studio 2012 or newer. A lot of value comes from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found