public Task RemoveReferenceAsync(string name)
 {
     return(GuiSyncDispatchAsync(async() => {
         ProjectReference referenceProjectItem = FindReference(name);
         if (referenceProjectItem != null)
         {
             packageManagementEvents.OnReferenceRemoving(referenceProjectItem);
             await ProjectReferenceMaintainer.RemoveReference(referenceProjectItem);
             LogRemovedReferenceFromProject(referenceProjectItem);
         }
     }));
 }
        ProjectReference FindReference(string name)
        {
            string referenceName = GetReferenceName(name);

            foreach (ProjectReference referenceProjectItem in ProjectReferenceMaintainer.GetReferences())
            {
                string projectReferenceName = GetProjectReferenceName(referenceProjectItem.Reference);
                if (IsMatchIgnoringCase(projectReferenceName, referenceName))
                {
                    return(referenceProjectItem);
                }
            }
            return(null);
        }
        async Task ExecuteAsync(CancellationToken cancellationToken)
        {
            var resolutionContext = CreateResolutionContext();

            actions = await packageManager.PreviewUpdatePackagesAsync(
                PackageId,
                project,
                resolutionContext,
                context,
                primarySources,
                new SourceRepository[0],
                cancellationToken);

            if (!actions.Any())
            {
                packageManagementEvents.OnNoUpdateFound(dotNetProject);
                return;
            }

            await CheckLicenses(cancellationToken);

            SetDirectInstall();

            using (IDisposable fileMonitor = CreateFileMonitor()) {
                using (var referenceMaintainer = new ProjectReferenceMaintainer(project)) {
                    await packageManager.ExecuteNuGetProjectActionsAsync(
                        project,
                        actions,
                        context,
                        resolutionContext.SourceCacheContext,
                        cancellationToken);

                    await referenceMaintainer.ApplyChanges();
                }
            }

            packageManager.ClearDirectInstall(context);

            project.OnAfterExecuteActions(actions);

            await project.RunPostProcessAsync(context, cancellationToken);
        }
        async Task AddReferenceToProject(ProjectReference assemblyReference)
        {
            await ProjectReferenceMaintainer.AddReference(assemblyReference);

            LogAddedReferenceToProject(assemblyReference);
        }