Referencing system.management.automation.dll in Vi

2019-01-07 04:50发布

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?

8条回答
何必那么认真
2楼-- · 2019-01-07 05:15

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.

查看更多
疯言疯语
3楼-- · 2019-01-07 05:17

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!

查看更多
beautiful°
4楼-- · 2019-01-07 05:18

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:\
查看更多
劳资没心,怎么记你
5楼-- · 2019-01-07 05:20

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.

查看更多
做自己的国王
6楼-- · 2019-01-07 05:25

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\

查看更多
迷人小祖宗
7楼-- · 2019-01-07 05:28

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.

查看更多
登录 后发表回答