点网发布不发布DLL到发布目录

时间:2019-02-22 15:06:40

标签: c# .net-core nuget

我想发布自己的.NET Core(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”,   版本= 1.0.0.0,文化=中性,PublicKeyToken = 31bf3856ad364e35'。   该系统找不到指定的文件。在   ConsoleApp1.Program.Main(String [] args)

要复制

1)创建一个简单的.NET Core控制台应用程序(我测试了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)运行编译的可执行文件

1 个答案:

答案 0 :(得分:6)

MMI package由Windows版本专用的多个程序集组成,例如:win10-x64win10-x86 win8-x64等。

因此,必须使用特定于版本的目标运行时(例如:win10-x64)而不是通用的win-x64。使用下面的发布命令,发布过程中将包含MMI DLL。

dotnet publish -c Release --self-contained -r win10-x64 ConsoleApp1
相关问题