Пример #1
0
        /// <summary>
        ///     Adds the project reference.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        public void AddProjectReference(Guid projectId)
        {
            if (ProjectGuid == projectId)
            {
                return;
            }

            ProjectNode referencedProject = new ProjectNode(Solution, projectId);

            if (VsProject != null)
            {
                if (VsProject.Object is VSProject project)
                {
                    References references = project.References;

                    if (references != null && referencedProject.ExtObject is EnvDTE.Project)
                    {
                        references.AddProject(referencedProject.ExtObject as EnvDTE.Project);
                    }
                }
                else
                {
                    AssemblyReferences references = (VsProject.Object as VSWebSite)?.References;

                    if (references != null && referencedProject.ExtObject is EnvDTE.Project)
                    {
                        try
                        {
                            references.AddFromProject(referencedProject.ExtObject as EnvDTE.Project);
                        }
                        catch (COMException)
                        {
                            //Web projects throws exceptions if the reference already exists
                        }
                    }
                }
            }
        }