Example #1
0
        private void RegisterAutoRebuildService()
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // Create build watcher. No need to unadvise, as this only happens once anyway.
            var solution     = (IVsSolution)GetGlobalService(typeof(IVsSolution));
            var buildManager = (IVsSolutionBuildManager)GetService(typeof(SVsSolutionBuildManager));
            var buildWatcher = new BuildEventsWatcher(solution, buildManager);
            var hr           = buildManager.AdviseUpdateSolutionEvents(buildWatcher, out var cookie);

            Marshal.ThrowExceptionForHR(hr);

            new AutoRebuildService(buildWatcher).Listen();
        }
Example #2
0
        protected async override Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            await JoinableTaskFactory.SwitchToMainThreadAsync();

            // Create build watcher. No need to unadvise, as this only happens once anyway.
            var solution = (IVsSolution) await GetServiceAsync(typeof(IVsSolution));

            var buildManager = (IVsSolutionBuildManager) await GetServiceAsync(typeof(SVsSolutionBuildManager));

            // According to the docs, this can happen if VS shuts down while our package is loading.
            if (solution == null || buildManager == null)
            {
                var buildWatcher = new BuildEventsWatcher(solution, buildManager);
                var hr           = buildManager.AdviseUpdateSolutionEvents(buildWatcher, out var cookie);
                Marshal.ThrowExceptionForHR(hr);

                new AutoRebuildService(buildWatcher).Listen();
            }
        }
Example #3
0
 public AutoRebuildService(BuildEventsWatcher buildEventsWatcher)
 {
     _buildEventsWatcher = buildEventsWatcher ?? throw new ArgumentNullException(nameof(buildEventsWatcher));
     _pipeName           = $"BlazorAutoRebuild\\{Process.GetCurrentProcess().Id}";
 }