msi*_*nfo 1 .net c# powershell
系统:Windows 7 Professional 64 位,PowerShell v 2.0,无Visual Studio(无法安装等)
尝试从 C# 运行 PowerShell。这是代码片段:
using System;
using System.Management.Automation;
class Hello {
static void Main(string[] args) {
PowerShell ps = PowerShell.Create();
ps.AddCommand("Get-Process");
Console.WriteLine("Process Id");
Console.WriteLine("----------------------------");
foreach (PSObject result in ps.Invoke()) {
Console.WriteLine(
"{0,-24}{1}",
result.Members["ProcessName"].Value,
result.Members["Id"].Value);
}
}
}
Run Code Online (Sandbox Code Playgroud)
错误:
e:\foo.cs(2,25):错误 CS0234:命名空间“System.Management”中不存在类型或命名空间名称“Automation”(您是否缺少程序集引用?)
由于没有 Visual Studio,我以原始方式运行代码。由于错误,我http://www.dll-found.com/system.management.automation.dll_download.html按照说明从dir下载了 dll并将其放置在 dir 中。重启机器后,没有成功。
首先,我想问一个普遍的问题。如何安装丢失的程序集或 dll 文件(仅限),因为对于某些人,您可能必须安装整个 Windows 或 PowerShell SDK 或 .NET Framework。
编辑
我已将下载的 dll 文件放在 C:\Windows\SysWOW64、C:\Windows\system32、C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5 和 C:\Program Files\Reference Assemblies\Microsoft\框架\v3.0.
我正在编译使用: C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:exe /out:E:\foo.exe E:\foo.cs
Flo*_*ter 11
警告:在任何理智的情况下,切勿从随机网站下载 DLL。尽可能使用 NuGet 包(或您的项目首选的包管理器)。如果找不到 DLL,几乎总是有充分的理由,您需要找出它是什么并修复它,而不仅仅是从 Internet 获取 DLL。
如果您在将旧项目重新定位到 .NET 4.8 等目标后遇到此问题,那么这是因为 NuGet 包名称已更改。
System.Management.AutomationMicrosoft.PowerShell.5.1.ReferenceAssemblies(NuGet)该包名称出现在命名空间中的类的文档System.Management.Automation中。
您必须使用/reference命令行参数,如MSDNcsc.exe中所述:
C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /reference:system.management.automation.dll /target:exe /out:E:\foo.exe /E:\foo.cs
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16598 次 |
| 最近记录: |