Exemplo n.º 1
0
        private void OnEnvDTEProjectRenamed(Project envDTEProject, string oldName)
        {
            NuGetUIThreadHelper.JoinableTaskFactory.Run(async() =>
            {
                if (!string.IsNullOrEmpty(oldName) && await IsSolutionOpenAsync() && _solutionOpenedRaised)
                {
                    await NuGetUIThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();

                    await EnsureNuGetAndVsProjectAdapterCacheAsync();

                    if (await EnvDTEProjectUtility.IsSupportedAsync(envDTEProject))
                    {
                        RemoveVsProjectAdapterFromCache(oldName);

                        var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(envDTEProject);
                        await AddVsProjectAdapterToCacheAsync(vsProjectAdapter);

                        _projectSystemCache.TryGetNuGetProject(envDTEProject.Name, out var nuGetProject);

                        NuGetProjectRenamed?.Invoke(this, new NuGetProjectEventArgs(nuGetProject));

                        // VSSolutionManager susbscribes to this Event, in order to update the caption on the DocWindow Tab.
                        // This needs to fire after NugetProjectRenamed so that PackageManagerModel has been updated with
                        // the right project context.
                        AfterNuGetProjectRenamed?.Invoke(this, new NuGetProjectEventArgs(nuGetProject));
                    }
                    else if (await EnvDTEProjectUtility.IsSolutionFolderAsync(envDTEProject))
                    {
                        // In the case where a solution directory was changed, project FullNames are unchanged.
                        // We only need to invalidate the projects under the current tree so as to sync the CustomUniqueNames.
                        foreach (var item in await EnvDTEProjectUtility.GetSupportedChildProjectsAsync(envDTEProject))
                        {
                            RemoveVsProjectAdapterFromCache(item.FullName);

                            var vsProjectAdapter = await _vsProjectAdapterProvider.CreateAdapterForFullyLoadedProjectAsync(item);
                            if (await vsProjectAdapter.IsSupportedAsync())
                            {
                                await AddVsProjectAdapterToCacheAsync(vsProjectAdapter);
                            }
                        }
                    }
                }
            });
        }