C#中引用dll问题汇总
开发C#过程中遇到很多的问题踩坑记录。
C#调用powershell引用System.Management.Automation.dll
在代码中 using System.Management.Automation; 是无法直接引用的。
![](https://zgao.top/wp-content/uploads/2022/04/iShot2022-04-21-11.14.06.png)
使用NuGet管理包。
![](https://zgao.top/wp-content/uploads/2022/04/iShot2022-04-21-11.13.42-1024x508.png)
查找Automation并添加后,发现并没有用。报错提示error: Error while adding package ‘Microsoft.PowerShell.5.ReferenceAssemblies’ to project ‘C:\Users\Administrator\Documents\xxxx.csproj’. The project does not support adding package references through the add package command.
![](https://zgao.top/wp-content/uploads/2022/04/image-45-1024x462.png)
网上的解释为NuGet只能添加NET core的包管理,我这里是NET framework开发的winform,所以失败了。
找了网上另一种解决方案。这里不确定每个人的目录是否一致。
C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management.Automation\v4.0_3.0.0.0__31bf3856ad364e35
![](https://zgao.top/wp-content/uploads/2022/04/image-47-1024x753.png)
这里添加引用后即可。
赞赏微信赞赏
支付宝赞赏
发表评论