public async Task ReloadSolutionAsync()

in src/Microsoft.VisualStudio.SlnGen.Extension/SlnGenPackage.cs [43:96]


        public async Task<int> ReloadSolutionAsync(CancellationToken cancellationToken)
        {
            if (_isSolutionReloading == 1 || Interlocked.Increment(ref _isSolutionReloading) != 1)
            {
                return 0;
            }

            try
            {
                await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

                IVsSolution solution = await GetServiceAsync(typeof(SVsSolution)) as IVsSolution;

                Assumes.Present(solution);

                List<IVsProject> projects = solution.GetProjects().ToList();

                if (projects.Count != 1)
                {
                    return 0;
                }

                string project = projects.Select(i => i.GetFullPath()).FirstOrDefault(i => !string.IsNullOrWhiteSpace(i));

                int result = solution.CloseSolutionElement((uint)__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave, null, 0);

                ErrorHandler.ThrowOnFailure(result);

                result = await RunSlnGenAsync(project, cancellationToken);

                ErrorHandler.ThrowOnFailure(result);

                result = solution.OpenSolutionFile((uint)__VSSLNOPENOPTIONS.SLNOPENOPT_Silent, Path.ChangeExtension(project, "sln"));

                ErrorHandler.ThrowOnFailure(result);

                if (SolutionCookie == default)
                {
                    _solutionEvents ??= new SolutionEvents(this);

                    result = solution.AdviseSolutionEvents(_solutionEvents, out uint cookie);

                    ErrorHandler.ThrowOnFailure(result);

                    SolutionCookie = cookie;
                }

                return result;
            }
            finally
            {
                Interlocked.Decrement(ref _isSolutionReloading);
            }
        }