C# Windows Powershell SDK 和 System.Management.Automation.PSObject
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1864534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Windows Powershell SDK and System.Management.Automation.PSObject
提问by xarzu
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
我在 Windows Server(我猜是 2008)SP 2 64 位操作系统上的 Visual Studio 2008 中编译的 ac 锐利程序中存在构建错误。它说“System.Management.Automation.PSObject”是在未引用的程序集中定义的。我在 MSDN 中进行了一些搜索,发现这似乎是 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.
问题是我已经有了 Windows Powershell。如果这就是我所需要的,我如何使用它或在 C Sharp IDE 中引用它。如果我需要下载一些额外的东西(即 SDK),我应该去哪里安装并安装它?我在网上找不到任何东西。
采纳答案by Keith Hill
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 SDKwhich will put the file in the above location.
查找C:\Program Files\Reference Assemblies\Microsoft\WindowsPowerShell\v1.0
System.Management.Automation.dll,如果存在,请将其添加为 C# 项目中的引用。如果它不存在,则下载Windows SDK,它将把文件放在上面的位置。
回答by Josh
If you can't find it there, type this at a PowerShell prompt.
如果在那里找不到它,请在 PowerShell 提示符下键入。
Copy ([PSObject].Assembly.Location) ~/Desktop
回答by Start-Automating
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.
要正确引用 PowerShell,您应该在 GAC 中引用 PowerShell。Vista SDK 附带的 PowerShell 是 PowerShell V1.0,无论安装什么,此技术都将引用 1.0、2.0 或 X.0。引用 SDK 程序集也不会创建最可移植的项目,因为您必须安装 SDK 来构建项目,而不仅仅是 Visual Studio 和 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.
不幸的是,引用 GAC 项并不是 Visual Studio UI 干净利落的事情,因此您必须手动编辑 CSProj 文件。找到包含元素的部分,并添加此引用元素。
<Reference Include="System.Management.Automation" />
This will reference the latest System.Management.Automation installed on the system, no matter what version it is.
这将引用系统上安装的最新 System.Management.Automation,无论它是什么版本。
Hope this helps
希望这可以帮助