Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/332.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 对在PowerShell中添加程序集以使用.NET类感到困惑_C#_.net_Powershell - Fatal编程技术网

C# 对在PowerShell中添加程序集以使用.NET类感到困惑

C# 对在PowerShell中添加程序集以使用.NET类感到困惑,c#,.net,powershell,C#,.net,Powershell,我希望得到一些澄清。在PowerShell中使用.NET Framework类时,有时必须将程序集加载到内存中,我们必须在PowerShell中使用Add-Type Cmdlet。例如,如果我想使用System.ServiceProcess.ServiceController类,我会这样做 Add-Type -AssemblyName System.ServiceProcess 但这就是我感到困惑的地方。文档中说System.ServiceProcess.ServiceController类

我希望得到一些澄清。在PowerShell中使用.NET Framework类时,有时必须将程序集加载到内存中,我们必须在PowerShell中使用Add-Type Cmdlet。例如,如果我想使用System.ServiceProcess.ServiceController类,我会这样做

Add-Type -AssemblyName System.ServiceProcess

但这就是我感到困惑的地方。文档中说System.ServiceProcess.ServiceController类有两个程序集

即:System.ServiceProcess.ServiceController.dll、System.ServiceProcess.dll

无论我添加哪一个,它似乎都有效,但我想知道发动机罩下发生了什么

更令人困惑的是Process类:

这里我们有3个程序集:System.Diagnostics.Process.dll、System.dllnetstandard.dll

我只能加载System.Dll。另外两个简单地说程序集找不到

所以问题是,如果我想使用和.NET Framework类,我假设我应该拥有所有的aasemblies,那么如何在PowerShell中加载它们呢

希望这是明确的,谢谢你的回答

亲切问候,


John

System.ServiceProcess.dll位于GAC中,是.NET Framework的一部分。
System.ServiceProcess.ServiceController.dll
是核心CLR的一部分

但请稍候—PowerShell是基于.NET Framework CLR的

如果您根据正确的方法构建程序集,并且其依赖项是可解析的,那么它应该能够在.NET Framework上运行

您可以看到,
System.ServiceProcess.dll
引用了
kernel32
,而
System.ServiceProcess.ServiceController.dll
参考
api ms win服务核心

大致相同,但核心CLR版本的功能可能会更少

至于其他名称空间,大多数
System
名称空间位于
mscorlib
System.dll
中。近年来,人们一直在努力通过将it的部分移出,实现带外交付

例如,
System.Diagnostics.Process.dll
现在作为一个组件提供,这使得用户能够更快地进行部署,而不是提供目标需要安装的主要.NET Framework更新


如果您使用的是常规Powershell而不是,那么您可以只引用.NET Framework程序集,而不会看到令人困惑的

系统。ServiceProcess.dll
位于GAC中,并且是.NET Framework的一部分。
System.ServiceProcess.ServiceController.dll
是核心CLR的一部分

但请稍候—PowerShell是基于.NET Framework CLR的

如果您根据正确的方法构建程序集,并且其依赖项是可解析的,那么它应该能够在.NET Framework上运行

您可以看到,
System.ServiceProcess.dll
引用了
kernel32
,而
System.ServiceProcess.ServiceController.dll
参考
api ms win服务核心

大致相同,但核心CLR版本的功能可能会更少

至于其他名称空间,大多数
System
名称空间位于
mscorlib
System.dll
中。近年来,人们一直在努力通过将it的部分移出,实现带外交付

例如,
System.Diagnostics.Process.dll
现在作为一个组件提供,这使得用户能够更快地进行部署,而不是提供目标需要安装的主要.NET Framework更新


如果您使用的是常规Powershell,而不是,则只需引用.NET Framework程序集,就不会出现混乱的情况

MSDN无法在.NET Framework、.NET Core或.NET Standard中正确指示属于哪个程序集的类型

您可以改为使用:


MSDN无法在.NET Framework、.NET Core或.NET标准中正确指示属于哪个程序集的类型

您可以改为使用: