我想发布我自己包含的.NET核心(2.2)应用程序,但是一个特定的NuGet包(Microsoft.Management.Infrastructure)从未发布到publish文件夹中(就像在.dll文件中不存在的那样)。
我使用的是命令dotnet publish -c Release --self-contained -r win-x64 ConsoleApp1。在visual studio中运行应用程序时,一切都正常。但是,在运行编译后的可执行文件时,我会得到一个FileNotFoundException
未处理的异常: System.IO.FileNotFoundException:无法加载文件或程序集'Microsoft.Management.Infrastructure,Version=1.0.0.0,Culture=neutral,PublicKeyToken=31bf3856ad364e35‘。系统找不到指定的文件。在ConsoleApp1.Program.Main(String[] args)
再生产
1)创建一个简单的.NET核心控制台应用程序(我测试了2.1和2.2,没有区别)
2)添加NuGet包Microsoft.Management.Infrastructure
3)在应用程序中添加以下代码:
namespace ConsoleApp1
{
internal class Program
{
private static void Main(string[] args)
{
var sessionOptions = new DComSessionOptions
{
Timeout = TimeSpan.FromSeconds(30)
};
CimSession Session = CimSession.Create("localhost", sessionOptions);
var processors = Session.QueryInstances(@"root\cimv2", "WQL", "SELECT * FROM Win32_Processor");
foreach (CimInstance processor in processors)
{
Console.WriteLine(processor.CimInstanceProperties["Name"].Value);
}
Console.ReadLine();
}
}
}4)发布项目:dotnet publish -c Release --self-contained -r win-x64 ConsoleApp1
5)运行已编译的可执行文件
发布于 2019-02-24 16:58:15
MMI封装由多个特定于Windows版本的程序集组成,如:win10-x64、win10-x86 win8-x64等。
因此,您必须使用特定于版本的目标运行时(例如:win10-x64)而不是一般的win-x64。使用下面的发布命令,发布过程中包含了MMI DLL。
dotnet publish -c Release --self-contained -r win10-x64 ConsoleApp1https://stackoverflow.com/questions/54829926
复制相似问题