コード例 #1
0
ファイル: VsSolution.cs プロジェクト: yukiyuki/MyToolkit
        /// <summary>Loads all projects of the solution. </summary>
        /// <param name="ignoreExceptions">Specifies whether to ignore exceptions. </param>
        /// <param name="projectCache">The project cache with already loaded projects. </param>
        public void LoadProjects(bool ignoreExceptions, Dictionary <string, VsProject> projectCache)
        {
            var projects = new List <VsProject>();
            var array    = (Array)_solutionParser.GetPropertyValue("Projects");

            foreach (var projectObject in array)
            {
                try
                {
                    var relativePath = projectObject.GetPropertyValue("RelativePath").ToString();
                    var projectPath  = System.IO.Path.GetFullPath(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Path), relativePath));
                    if (projectPath.ToLower().EndsWith(".csproj") && File.Exists(projectPath))
                    {
                        if (projectCache != null && projectCache.ContainsKey(projectPath))
                        {
                            projects.Add(projectCache[projectPath]);
                        }
                        else
                        {
                            projects.Add(VsProject.Load(projectPath));
                        }
                    }
                }
                catch (Exception)
                {
                    if (!ignoreExceptions)
                    {
                        throw;
                    }
                }
            }

            _projects = projects.OrderBy(p => p.Name).ToList();
        }
コード例 #2
0
        /// <summary>Loads all projects of the solution.</summary>
        /// <param name="ignoreExceptions">Specifies whether to ignore exceptions.</param>
        /// <param name="projectCache">The project cache with already loaded projects.</param>
        /// <param name="errors">The loading errors (out param).</param>
        public void LoadProjects(bool ignoreExceptions, Dictionary <string, VsProject> projectCache, Dictionary <string, Exception> errors = null)
        {
            var projects = new List <VsProject>();
            var array    = _solution.ProjectsInOrder;

            foreach (var projectObject in array)
            {
                try
                {
                    var relativePath = projectObject.RelativePath;
                    var projectPath  = System.IO.Path.GetFullPath(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Path), relativePath));
                    try
                    {
                        if (projectPath.ToLower().EndsWith(".csproj") && File.Exists(projectPath))
                        {
                            if (projectCache != null && projectCache.ContainsKey(projectPath))
                            {
                                projects.Add(projectCache[projectPath]);
                            }
                            else
                            {
                                projects.Add(VsProject.Load(projectPath, _projectCollection));
                            }
                        }
                    }
                    catch (Exception exception)
                    {
                        if (!ignoreExceptions)
                        {
                            throw;
                        }
                        if (errors != null)
                        {
                            errors[projectPath] = exception;
                        }
                    }
                }
                catch
                {
                    if (!ignoreExceptions)
                    {
                        throw;
                    }
                }
            }

            _projects = projects.OrderBy(p => p.Name).ToList();

            foreach (var project in _projects)
            {
                if (!project.Solutions.Contains(this))
                {
                    project.Solutions.Add(this);
                }
            }
        }
コード例 #3
0
 /// <summary>Gets all referenced project files of a given Visual Studio project file. </summary>
 /// <param name="projectPath">The project file path. </param>
 /// <returns>The referenced project files. </returns>
 public static IEnumerable <string> GetProjectReferences(string projectPath)
 {
     return(VsProject.Load(projectPath).ProjectReferences.Select(p => p.Path));
 }
コード例 #4
0
 /// <summary>Sorts the given projects in their required build order. </summary>
 /// <param name="projectPaths">The project files. </param>
 /// <param name="projectCollection">The project collection.</param>
 /// <returns>The project file paths in the correct build order. </returns>
 public static IEnumerable <string> GetBuildOrder(IEnumerable <string> projectPaths, ProjectCollection projectCollection)
 {
     return(projectPaths.Select(p => VsProject.Load(p, projectCollection))
            .SortByBuildOrder().Select(p => p.Path));
 }