可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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?
回答1:
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!
回答2:
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\
回答3:
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:\
回答4:
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.
回答5:
if it is 64bit them - C:\Program Files (x86)\Reference Assemblies\Microsoft\WindowsPowerShell**3.0**
and version could be different
回答6:
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.
回答7:
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.
回答8:
You can also use nuget: https://www.nuget.org/packages/System.Management.Automation/
It is maybe a better option.