Windows Powershell SDK and System.Management.Automation.PSObject

可紊 提交于 2019-12-04 11:39:27

问题


I have a build error in a c sharp program that I am compiling in Visual Studio 2008 on a Windows Server (2008, I guess) SP 2 64-BIT OS. It says that 'System.Management.Automation.PSObject' is defined in an assembly that is not referenced. I did some searching in MSDN and I found that this seems to be part of the Windows Power Shell SDK. http://msdn.microsoft.com/en-us/library/system.management.automation.psobject(VS.85).aspx

The problem is that I already have the Windows Powershell. If this is all I need, how do I make use of it or reference it in the C Sharp IDE. If I need to download something extra (ie the SDK), where do I go to do this and install it? I could not find anything online.


回答1:


Look in C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0 for System.Management.Automation.dll and if it exists, add it as a reference in your C# project. If it doesn't exist, then download the Windows SDK which will put the file in the above location.




回答2:


If you can't find it there, type this at a PowerShell prompt.

Copy ([PSObject].Assembly.Location) ~/Desktop



回答3:


To correctly reference PowerShell, you should reference the PowerShell inside the GAC. The PowerShell included with the Vista SDK is PowerShell V1.0, and this technique will reference 1.0, 2.0, or X.0, whatever is installed. Referencing the SDK assembly will also not create the most portable of projects, because you have to have the SDK installed to build the project, rather than just Visual Studio and Windows.

Unfortunately, referencing GAC items is not something the visual studio UI does cleanly, so you have to go hand edit the CSProj file. Find the section with elements, and add this reference element.

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

This will reference the latest System.Management.Automation installed on the system, no matter what version it is.

Hope this helps



来源:https://stackoverflow.com/questions/1864534/windows-powershell-sdk-and-system-management-automation-psobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!