Ejemplo n.º 1
0
        /// <summary>
        /// Finds a project in the solution, given its output assembly name.
        /// </summary>
        /// <returns>A <see cref="Project"/> reference or <see langword="null" /> if
        /// it doesn't exist. Project can be C# or VB.</returns>
        public static Project FindProjectByAssemblyName(_DTE vs, string name)
        {
            if (vs == null)
            {
                throw new ArgumentNullException("vs");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            try
            {
                foreach (Project p in (Projects)vs.GetObject("CSharpProjects"))
                {
                    if (p.Properties.Item("AssemblyName").Value.ToString() == name)
                    {
                        return(p);
                    }
                }
            }
            catch { } // Late-bound collection of "CSharpProject" throws if C# is not installed.
            try
            {
                foreach (Project p in (Projects)vs.GetObject("VBProjects"))
                {
                    if (p.Properties.Item("AssemblyName").Value.ToString() == name)
                    {
                        return(p);
                    }
                }
            }
            catch { } // Late-bound collection of "VBProjects" throws if VB is not installed.

            return(null);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Finds a project in the solution, given its name.
        /// </summary>
        /// <returns>A <see cref="Project"/> reference or <see langword="null" /> if
        /// it doesn't exist. Project can be C# or VB.</returns>
        public static Project FindProjectByName(_DTE vs, string name)
        {
            if (vs == null)
            {
                throw new ArgumentNullException("vs");
            }
            if (name == null)
            {
                throw new ArgumentNullException("name");
            }
            // Try the quick ones first.
            try
            {
                foreach (Project p in (Projects)vs.GetObject("CSharpProjects"))
                {
                    if (p.Name == name)
                    {
                        return(p);
                    }
                }
            }
            catch { } // Late-bound collection of "CSharpProject" throws if C# is not installed.

            try
            {
                foreach (Project p in (Projects)vs.GetObject("VBProjects"))
                {
                    if (p.Name == name)
                    {
                        return(p);
                    }
                }
            }
            catch { } // Late-bound collection of "VBProjects" throws if VB is not installed.

            // We've no option but to iterate everything now.
            foreach (Project p in vs.Solution.Projects)
            {
                if (p.Name == name)
                {
                    return(p);
                }
                else if (p.ProjectItems != null)
                {
                    Project inner = FindProjectByName(p.ProjectItems, name);
                    if (inner != null)
                    {
                        return(inner);
                    }
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// This method return Visual C++ Language Manager
        /// </summary>
        /// <param name="dte">Automation IDE Object</param>
        /// <returns>Return Visual C++ Language Manager</returns>
        /// <exception cref="ArgumentNullException"></exception>
        public static VCLanguageManager GetVCLanguageManager(_DTE dte)
        {
            if (dte == null)
            {
                throw new ArgumentNullException("dte");
            }

            return(( VCLanguageManager )dte.GetObject("VCLanguageManager"));
        }