V
V
Vladimir Korotenko2020-11-27 15:51:33
linux
Vladimir Korotenko, 2020-11-27 15:51:33

FileSystemWatcher does not work in Linux when adding packages, how to fix it?

So the problem is that this program stops working when adding packages

using System;
using System.Diagnostics;
using System.IO;
using System.Threading;

namespace watcher
{
    internal class Program
    {
        private const string FileName = "params.json";
        private static string _exePath;
        private static int Main(string[] args)
        {
            if (args.Length < 2) return ShowHelp();
            var watchFolder = args[0];
            _exePath = args[1];
            var watcher = new FileSystemWatcher
            {
                Path = watchFolder,
                Filter = FileName,
                IncludeSubdirectories = true,
                NotifyFilter = NotifyFilters.LastAccess |
                               NotifyFilters.LastWrite |
                               NotifyFilters.FileName |
                               NotifyFilters.DirectoryName,
                EnableRaisingEvents = true
            };
            watcher.Created += OnChanged;

            while (true)
            {
                Thread.Sleep(1000);
            }
        }

        private static int ShowHelp()
        {
            Console.WriteLine("usage: watcher path_to_watch_folder path_to_executable");
            return -1;
        }

        private static void OnChanged(object sender, FileSystemEventArgs e)
        {
            Console.WriteLine(e.FullPath);
            Process.Start(_exePath, e.FullPath);
        }
    }
}


Project file that works
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

</Project>


not working
<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net5.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Dapper" Version="2.0.78" />
    <PackageReference Include="Microsoft.Extensions.Options" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.CommandLine" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
    <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.0" />
    <PackageReference Include="Pomelo.Data.MySql.Unofficial" Version="1.0.1" />
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
  </ItemGroup>

  <ItemGroup>
    <None Update="appsettings.Debug.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.Production.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="appsettings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\e280116060000206126d2423_0.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\e280116060000206126d2423_1.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\e280116060000206126d2423_2.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\e280116060000206126d2423_3.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\e280116060000206126d2423_4.jpg">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
    <None Update="Data\20200817T182946\params.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  
</Project>


Moreover, which is extremely unpleasant, everything works under windows, but nothing at all under Linux after adding packages.

Bypassed by installing a minimal program as a service, and running the handler program through process creation. But this is some kind of PHP way. I would like to pack everything into one file and get rid of calling other processes.
Haven't encountered this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-11-28
@d-stream

And if you make publish - will there be files?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question