コード例 #1
0
ファイル: ProjectNode.cs プロジェクト: vijumn/open-wssf-2015
        /// <summary>
        /// Adds the assembly reference.
        /// </summary>
        /// <param name="assemblyPath">The assembly path.</param>
        public void AddAssemblyReference(string assemblyPath)
        {
            Guard.ArgumentNotNullOrEmptyString(assemblyPath, "assemblyPath");

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

                    if (references != null)
                    {
                        references.Add(assemblyPath);
                    }
                }
                else if (VSProject.Object is VsWebSite.VSWebSite)
                {
                    VsWebSite.AssemblyReferences references =
                        ((VsWebSite.VSWebSite)VSProject.Object).References;

                    if (references != null)
                    {
                        if (System.IO.Path.IsPathRooted(assemblyPath))
                        {
                            references.AddFromFile(assemblyPath);
                        }
                        else
                        {
                            references.AddFromGAC(assemblyPath);
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: ProjectNode.cs プロジェクト: vijumn/open-wssf-2015
        /// <summary>
        /// Adds the project reference.
        /// </summary>
        /// <param name="projectId">The project id.</param>
        public void AddProjectReference(Guid projectId)
        {
            if (ProjectGuid == projectId)
            {
                return;
            }

            using (ProjectNode referencedProject = new ProjectNode(Solution, projectId))
            {
                if (VSProject != null)
                {
                    try
                    {
                        if (VSProject.Object is VSLangProj.VSProject)
                        {
                            VSLangProj.References references =
                                ((VSLangProj.VSProject)VSProject.Object).References;

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

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