PowerShell使用netcoreapp3.0程序集:Add-Type失败,提示“无法从程序集'System.Private.CoreLib'中加载类型'System.Object'”。

5
我需要在 PowerShell 脚本中使用我的一个 .NET Core 3 组件:
try { 
    Add-Type -Path "app.dll" 
}
catch { 
    $_.Exception.LoaderExceptions 
}

这个失败了:

Could not load type 'System.Object' from assembly 'System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e' because the parent does 
not exist.

当我尝试添加“System.Private.CoreLib.lib”类型时,出现相同的错误。似乎使用netstandard2.0程序集效果良好,但不适用于我的netcoreapp3.0程序集。我可以采取什么措施才能在PowerShell脚本中使用我的程序集方法?
1个回答

0
如果你需要在PowerShell中加载针对netstandard2.0以上版本的.NET程序集,那么你应该尝试在PowerShell Core 7.1.3或以上版本中执行你的脚本。
Windows PowerShell可能只能加载针对.NET Framework或netstandard2.0的.NET程序集。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接