首页 > 解决方案 > 使用 .NetCore 3.1 运行修剪过的自包含单个可执行文件 - 无法加载文件或程序集“Microsoft.Management.Infrastructure

问题描述

我在以 .Net Core 3.1 作为目标框架的控制台应用程序中调用 PowerShell 脚本。当我在调试模式下运行解决方案时,PowerShell 命令工作正常,但是当我运行 Trimmed Self-Contained Single Executable 时,出现以下错误:

出现异常System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.Management.Infrastructure,版本=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35”。该系统找不到指定的文件。文件名:System.Reflection.RuntimeAssembly.GetExportedTypes() 中 System.Reflection.Assembly.get_ExportedTypes() 中的“Microsoft.Management.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35” System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection 中的 .Runspaces.PSSnapInHelpers.GetAssemblyTypes(程序集程序集,字符串名称)(程序集程序集,字符串名称,PSSnapInInfo psSnapInInfo,PSModuleInfo moduleInfo,字符串 helpFile,Dictionary2& cmdlet,Dictionary2& 别名,Dictionary2&

我尝试通过 Nuget 添加Microsoft.Management.Infrastructure包,但仍然存在同样的问题。有趣的是正在寻找 1.0.0.0 版本,而我的项目中安装了 2.0.0.0。如果有人对如何进行有任何建议,将不胜感激!

标签: c#.net-core-3.1powershell-7.0

解决方案


推荐阅读