Answer the question
In order to leave comments, you need to log in
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 Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
</PropertyGroup>
</Project>
<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>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question