Referencing system.management.automation.dll in Visual Studio

Visual StudioPowershell

Visual Studio Problem Overview


I am beginning to look into the PowerShell model and snap-in development. The first thing I notice is to reference System.management.automation.dll. However in Visual Studio, the .NET tab does not have that assembly, and nor is one able browse to

C:\windows\assembly\GAC_MSIL\System.Management.Automation\1.0.0.0__31bf3856ad364e35\System.Management.Automation.dll

to make a file-based reference.

Am i forced to copy the file out manually to make an easy reference?

Visual Studio Solutions


Solution 1 - Visual Studio

System.Management.Automation on Nuget

System.Management.Automation.dll on NuGet, newer package from 2015, not unlisted as the previous one!

Microsoft PowerShell team packages un NuGet

Update: package is now owned by PowerShell Team. Huzzah!

Solution 2 - Visual Studio

A copy of System.Management.Automation.dll is installed when you install the windows SDK (a suitable, recent version of it, anyway). It should be in C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0\

Solution 3 - Visual Studio

If you don't want to install the Windows SDK you can get the dll by running the following command in powershell:

Copy ([PSObject].Assembly.Location) C:\

Solution 4 - Visual Studio

I couldn't get the SDK to install properly (some of the files seemed unsigned, something like that). I found another solution here and that seems to work okay for me. It doesn't require installation of new files at all. Basically, what you do is:

Edit the .csproj file in a text editor, and add:

<Reference Include="System.Management.Automation" />

to the relevant section.

Hope this helps.

Solution 5 - Visual Studio

if it is 64bit them - C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell**3.0**

and version could be different

Solution 6 - Visual Studio

I used the VS Project Reference menu and browsed to: C:\windows\assembly\GAC_MSIL\System.Management.Automation and added a reference for the dll and the Runspaces dll.

I did not need to hack the .csprj file and add the reference line mentioned above. I do not have the Windows SDK installed.

I did do the Powershell copy mentioned above: Copy ([PSObject].Assembly.Location) C:\

My test with a Get-Process Powershell command then worked. I used examples from Powershell for developers Chapter 5.

Solution 7 - Visual Studio

The assembly coming with Powershell SDK (C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0) does not come with Powershell 2 specific types.

Manually editing the csproj file solved my problem.

Solution 8 - Visual Studio

You can also use nuget: https://www.nuget.org/packages/System.Management.Automation/ It is maybe a better option.

Solution 9 - Visual Studio

As @skfd alludes to above, the System.Management.Automation.dll package is available on NuGet if you are targeting .Net 4.8 or earlier, but is now delisted, so you need to install it manually. eg:

PM >Install-Package System.Management.Automation.dll -Version 10.0.10586

The System.Management.Automation package is also available if you are targeting .Net Core or Framework 5/6 and seems to be the supported package moving forward. You could also try installing this package and adding the reference manually, but YMMV.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionicelavaView Question on Stackoverflow
Solution 1 - Visual StudioskfdView Answer on Stackoverflow
Solution 2 - Visual StudiotomasrView Answer on Stackoverflow
Solution 3 - Visual Studiokravits88View Answer on Stackoverflow
Solution 4 - Visual StudioJP.View Answer on Stackoverflow
Solution 5 - Visual StudiopradeepView Answer on Stackoverflow
Solution 6 - Visual StudiodpminusaView Answer on Stackoverflow
Solution 7 - Visual StudioRaduView Answer on Stackoverflow
Solution 8 - Visual StudioNOWANView Answer on Stackoverflow
Solution 9 - Visual StudiomacsView Answer on Stackoverflow