【问题标题】:Cannot use FileSystemWatcher with coreclr on ubuntu无法在 ubuntu 上将 FileSystemWatcher 与 coreclr 一起使用
【发布时间】:2015-11-24 19:32:54
【问题描述】:

我正在尝试在 Ubuntu 的 coreclr 项目中使用 FileSystemWatcher 类,但出现以下异常:

未处理的异常:System.IO.FileNotFoundException:无法加载文件或程序集“System.IO.FileSystem.Watcher,版本=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。

我的 project.json 文件:

{
"version": "1.0.0-*",
"compilationOptions": {
    "emitEntryPoint": true
},

"dependencies": {
    "Microsoft.NETCore.Runtime": "1.0.1-beta-*",
    "System.IO": "4.0.11-beta-*",
    "System.IO.FileSystem.Watcher": "4.0.0-beta-*",
    "System.Console": "4.0.0-beta-*",
    "System.Runtime": "4.0.21-beta-*"
},

"frameworks": {
    "dnxcore50": { }
}
}

和 Program.cs:

using System;
using System.IO;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {            
            using (var watcher = new FileSystemWatcher("."))
            {
                Console.WriteLine("Watcher created!");    
            }
        }
    }
}

我做错了什么?

PS。 .NET Core 按照此站点的说明安装:https://dotnet.github.io/getting-started/

【问题讨论】:

  • 尝试在目录中运行dnu restore,是否成功?
  • @PavelKrymets:我就是这样开始的——尝试了 dotnet restore,dotnet run。我的控制台上没有可用的 dnu,但我认为“dotnet”只是 dnu 工具的别名。恢复过程中没有任何错误或警告,一切正常。
  • 漏掉你用的是dotnet,我再查一下
  • 尝试将依赖项中的 -beta 版本部分删除为 "4.0.0-* 等。
  • @PavelKrymets:没有区别 - dotnet restore 后的结果相同,dotnet run。

标签: .net ubuntu asp.net-core coreclr


【解决方案1】:

这是 project.json 的最小版本,可以与我的 Ubuntu VM 上的上述 Program.cs 文件完美配合:

{
  "dependencies": {
    "System.IO.FileSystem.Watcher": "4.0.0-beta-23516"
  },
  "frameworks": {
    "dnxcore50": {
      "dependencies": {
        "System.Console": "4.0.0-beta-23516"
      }
    }
  }
}

【讨论】:

    猜你喜欢
    • 2014-07-09
    • 1970-01-01
    • 2018-11-29
    • 1970-01-01
    • 1970-01-01
    • 2016-05-01
    • 1970-01-01
    • 2016-05-18
    • 2018-08-10
    相关资源
    最近更新 更多