You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.NET 7独立部署控制台程序在Linux运行失败

问题:.NET单文件程序在Linux运行报错Failed to create CoreCLR, HRESULT: 0x8007000E

我写了一个清理指定目录的控制台程序,代码如下:

static void Main(string[] args)
{
    string path = args.FirstOrDefault();

    if (string.IsNullOrWhiteSpace(path))
    {
        Console.WriteLine("Path not defined");
        Environment.Exit(-1);
    }

    if (!Directory.Exists(path))
    {
        Console.WriteLine("Directory not found");
        Environment.Exit(-1);
    }

    while (true)
    {
        try
        {
            Console.WriteLine("Getting ready files");
            var readyFiles = Directory.GetFiles(path, "*.ready").Select(c => Path.GetFileNameWithoutExtension(c));

            Console.WriteLine("Getting done files");
            var doneFiles = Directory.GetFiles(path, "*.done").Select(c => Path.GetFileNameWithoutExtension(c));

            Console.WriteLine("Getting dirs");
            var dirs = Directory.GetDirectories(path);

            foreach (var dir in dirs)
            {
                var name = Path.GetFileName(dir);
                if (readyFiles.Any(f => f.Equals(name)))
                {
                    continue;
                }

                if (!doneFiles.Any(f => f.Equals(name)))
                {
                    continue;
                }

                Console.WriteLine($"Removing {name}");
                Directory.Delete(dir, true);
                if (File.Exists($"{dir}.password"))
                {
                    File.Delete($"{dir}.password");
                }
            }
        }
        catch { }

        Thread.Sleep(5 * 60 * 1000);
    }
}

我将其发布为Linux-x64架构的独立单文件程序,发布配置如下:

<Project>
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net7.0\publish\linux-x64\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <_TargetId>Folder</_TargetId>
    <TargetFramework>net7.0</TargetFramework>
    <RuntimeIdentifier>linux-x64</RuntimeIdentifier>
    <SelfContained>true</SelfContained>
    <PublishSingleFile>true</PublishSingleFile>
    <PublishTrimmed>false</PublishTrimmed>
  </PropertyGroup>
</Project>

在Linux系统中执行chmod +x foldercleanup设置可执行权限后,运行程序出现报错:

Failed to create CoreCLR, HRESULT: 0x8007000E

我已经做了以下操作但问题仍未解决:

  • 用strace -f -o logfile ./foldercleanup生成了追踪日志
  • 参考了相关GitHub Issue并尝试其中的解决方案

寻求解决办法。

内容的提问来源于stack exchange,提问作者Snake Eyes

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 12:55:22