public void Start() { if (Debugger.IsAttached) { referenceBuilder = new EmptyTypeReferenceBuilder(); Logger.Log("Dynamic compilation disabled (debugger attached)."); return; } var di = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory); string basePath = getSolutionPath(di); if (!Directory.Exists(basePath)) { referenceBuilder = new EmptyTypeReferenceBuilder(); Logger.Log("Dynamic compilation disabled (no solution file found)."); return; } #if NET5_0 referenceBuilder = new RoslynTypeReferenceBuilder(); #else referenceBuilder = new EmptyTypeReferenceBuilder(); #endif Task.Run(async() => { Logger.Log("Initialising dynamic compilation..."); await referenceBuilder.Initialise(Directory.GetFiles(basePath, "*.sln").First()).ConfigureAwait(false); foreach (string dir in Directory.GetDirectories(basePath)) { // only watch directories which house a csproj. this avoids submodules and directories like .git which can contain many files. if (!Directory.GetFiles(dir, "*.csproj").Any()) { continue; } var fsw = new FileSystemWatcher(dir, @"*.cs") { EnableRaisingEvents = true, IncludeSubdirectories = true, NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.CreationTime | NotifyFilters.FileName, }; fsw.Renamed += onChange; fsw.Changed += onChange; fsw.Created += onChange; watchers.Add(fsw); } Logger.Log("Dynamic compilation is now available."); }); }