【问题标题】:Dotnet publish not publishing DLL to publish directorydotnet publish 不发布 DLL 到发布目录
【发布时间】:2019-02-22 15:06:40
【问题描述】:

我想发布我的自包含 .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) 运行编译后的可执行文件

【问题讨论】:

标签: c# .net-core nuget


【解决方案1】:

MMI package 由多个特定于 Windows 版本的程序集组成,即:win10-x64win10-x86win8-x64 等。

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

dotnet publish -c Release --self-contained -r win10-x64 ConsoleApp1

【讨论】:

  • 还是解决了问题!非常感谢
猜你喜欢
  • 1970-01-01
  • 2021-08-26
  • 1970-01-01
  • 1970-01-01
  • 2019-09-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多