public void OnCodeDirectoryAliasesChanged(ICSharpProjectRoot project, int previousAliasesCount, string[] previousAliases, int currentAliasesCount, string[] currentAliases)
        {
            CSharpProjectShim projectSite = GetProjectSite(project);

            using (VisualStudioProject.CreateBatchScope())
            {
                var existingProjectReference = VisualStudioProject.GetProjectReferences().Single(p => p.ProjectId == projectSite.VisualStudioProject.Id);

                VisualStudioProject.RemoveProjectReference(existingProjectReference);
                VisualStudioProject.AddProjectReference(new ProjectReference(existingProjectReference.ProjectId, ImmutableArray.Create(currentAliases), existingProjectReference.EmbedInteropTypes));
            }
        }
        /// <summary>
        /// Given a ICSharpProjectRoot instance, it returns the ProjectSite instance, throwing if it
        /// could not be obtained.
        /// </summary>
        private static CSharpProjectShim GetProjectSite(ICSharpProjectRoot project)
        {
            // Get the host back for the project
            Guid projectSiteGuid          = typeof(ICSharpProjectSite).GUID;
            CSharpProjectShim projectSite = project.GetProjectSite(ref projectSiteGuid) as CSharpProjectShim;

            // We should have gotten a ProjectSite back. If we didn't, that means we're being given
            // a project site that we didn't get BindToProject called on first which is a no-no by
            // the project system.
            if (projectSite == null)
            {
                throw new ArgumentException("finalProject was not properly sited with the languageServices service.", "finalProject");
            }

            return(projectSite);
        }
        public void RemoveReferenceToCodeDirectory(string assemblyFileName, ICSharpProjectRoot project)
        {
            CSharpProjectShim projectSite = GetProjectSite(project);

            if (!this.CurrentProjectReferencesContains(projectSite.Id))
            {
                throw new ArgumentException("The finalProject reference is not currently referenced by this finalProject.", "finalProject");
            }

            var projectReferences = GetCurrentProjectReferences().Where(r => r.ProjectId == projectSite.Id);

            foreach (var projectReference in projectReferences)
            {
                RemoveProjectReference(projectReference);
            }
        }
        public void RemoveReferenceToCodeDirectory(string assemblyFileName, ICSharpProjectRoot project)
        {
            CSharpProjectShim projectSite = GetProjectSite(project);

            var projectReferencesToRemove = VisualStudioProject.GetProjectReferences().Where(p => p.ProjectId == projectSite.VisualStudioProject.Id).ToList();

            if (projectReferencesToRemove.Count == 0)
            {
                throw new ArgumentException($"The project {nameof(project)} is not currently referenced by this project.");
            }

            foreach (var projectReferenceToRemove in projectReferencesToRemove)
            {
                VisualStudioProject.RemoveProjectReference(new ProjectReference(projectSite.VisualStudioProject.Id));
            }
        }
        public void AddReferenceToCodeDirectoryEx(string assemblyFileName, ICSharpProjectRoot project, CompilerOptions optionID)
        {
            CSharpProjectShim projectSite = GetProjectSite(project);

            AddProjectReference(new ProjectReference(projectSite.Id));
        }
        public void OnCodeDirectoryAliasesChanged(ICSharpProjectRoot project, int previousAliasesCount, string[] previousAliases, int currentAliasesCount, string[] currentAliases)
        {
            CSharpProjectShim projectSite = GetProjectSite(project);

            UpdateProjectReferenceAliases(projectSite, ImmutableArray.Create(currentAliases));
        }
        public void AddReferenceToCodeDirectoryEx(string assemblyFileName, ICSharpProjectRoot projectRoot, CompilerOptions optionID)
        {
            CSharpProjectShim projectSite = GetProjectSite(projectRoot);

            VisualStudioProject.AddProjectReference(new ProjectReference(projectSite.VisualStudioProject.Id, embedInteropTypes: optionID == CompilerOptions.OPTID_IMPORTSUSINGNOPIA));
        }