Пример #1
0
        private void Load()
        {
            string solutionDirectory = Path.GetDirectoryName(ProjectPath);

            using (StreamReader reader = new StreamReader(ProjectPath))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("Project("))
                    {
                        string[] parts         = line.Split(DELIMS);
                        string   vsProjectPath = PathSeparatorLookup.Replace(parts[2].Trim(TRIM_CHARS), Path.DirectorySeparatorChar.ToString());
                        string   vsProjectGuid = parts[3].Trim(TRIM_CHARS);

                        if (VSProject.IsProjectFile(vsProjectPath))
                        {
                            var vsProject = new VSProject(Path.Combine(solutionDirectory, vsProjectPath));

                            _projectLookup[vsProjectGuid] = vsProject;
                        }
                    }
                    else if (line.IndexOf(BUILD_MARKER) >= 0)
                    {
                        line = line.Trim();
                        int endBrace = line.IndexOf('}');

                        string    vsProjectGuid = line.Substring(0, endBrace + 1);
                        VSProject vsProject;
                        if (_projectLookup.TryGetValue(vsProjectGuid, out vsProject))
                        {
                            line = line.Substring(endBrace + 2);

                            int    split          = line.IndexOf(BUILD_MARKER) + 1;
                            string solutionConfig = line.Substring(0, split - 1);
                            int    bar            = solutionConfig.IndexOf('|');
                            if (bar >= 0)
                            {
                                solutionConfig = solutionConfig.Substring(0, bar);
                            }

                            string projectConfig = line.Substring(split + BUILD_MARKER.Length);
                            if (!vsProject.ConfigNames.Contains(projectConfig))
                            {
                                bar = projectConfig.IndexOf('|');
                                if (bar >= 0)
                                {
                                    projectConfig = projectConfig.Substring(0, bar);
                                }
                            }

                            SolutionConfig config = null;

                            if (_configs.ContainsKey(solutionConfig))
                            {
                                config = _configs[solutionConfig];
                            }
                            else
                            {
                                config = new SolutionConfig(solutionConfig);
                                _configs.Add(solutionConfig, config);
                            }

                            foreach (var subPackage in vsProject.GetTestPackage(projectConfig).SubPackages)
                            {
                                if (!config.Assemblies.Contains(subPackage.FullName))
                                {
                                    config.Assemblies.Add(subPackage.FullName);
                                }
                            }

                            //if (VSProject.IsProjectFile(vsProjectPath))
                            //    project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath)));
                        }
                    }

                    line = reader.ReadLine();
                }
            }
        }
Пример #2
0
        private void Load()
        {
            string solutionDirectory = Path.GetDirectoryName(ProjectPath);
            using (StreamReader reader = new StreamReader(ProjectPath))
            {
                string line = reader.ReadLine();
                while (line != null)
                {
                    if (line.StartsWith("Project("))
                    {
                        string[] parts = line.Split(DELIMS);
                        string vsProjectPath = parts[2].Trim(TRIM_CHARS);
                        string vsProjectGuid = parts[3].Trim(TRIM_CHARS);

                        if (VSProject.IsProjectFile(vsProjectPath))
                            _projectLookup[vsProjectGuid] = new VSProject(Path.Combine(solutionDirectory, vsProjectPath));
                    }
                    else if (line.IndexOf(BUILD_MARKER) >= 0)
                    {
                        line = line.Trim();
                        int endBrace = line.IndexOf('}');

                        string vsProjectGuid = line.Substring(0, endBrace + 1);
                        VSProject vsProject;
                        if (_projectLookup.TryGetValue(vsProjectGuid, out vsProject))
                        {
                            line = line.Substring(endBrace + 2);

                            int split = line.IndexOf(BUILD_MARKER) + 1;
                            string solutionConfig = line.Substring(0, split - 1);
                            int bar = solutionConfig.IndexOf('|');
                            if (bar >= 0)
                                solutionConfig = solutionConfig.Substring(0, bar);

                            string projectConfig = line.Substring(split + BUILD_MARKER.Length);
                            if (!vsProject.ConfigNames.Contains(projectConfig))
                            {
                                bar = projectConfig.IndexOf('|');
                                if (bar >= 0)
                                    projectConfig = projectConfig.Substring(0, bar);
                            }

                            SolutionConfig config = null;

                            if (_configs.ContainsKey(solutionConfig))
                                config = _configs[solutionConfig];
                            else
                            {
                                config = new SolutionConfig(solutionConfig);
                                _configs.Add(solutionConfig, config);
                            }

                            foreach (var subPackage in vsProject.GetTestPackage(projectConfig).SubPackages)
                                if (!config.Assemblies.Contains(subPackage.FullName))
                                    config.Assemblies.Add(subPackage.FullName);

                            //if (VSProject.IsProjectFile(vsProjectPath))
                            //    project.Add(new VSProject(Path.Combine(solutionDirectory, vsProjectPath)));
                        }
                    }

                    line = reader.ReadLine();
                }
            }
        }
Пример #3
0
 public bool CanLoadFrom(string path)
 {
     return(VSProject.IsProjectFile(path) || VSProject.IsSolutionFile(path));
 }
Пример #4
0
        private bool CheckProjectReferencesNunit(VSProject vsProject)
        {
            if (vsProject.MsBuildDocument == null)
                return true;

            var doc = vsProject.MsBuildDocument;
            var namespaceManager = new XmlNamespaceManager(doc.NameTable);
            namespaceManager.AddNamespace("msbuild", "http://schemas.microsoft.com/developer/msbuild/2003");

            var hasNunitReference =
                doc.SelectNodes("/msbuild:Project/msbuild:ItemGroup/msbuild:Reference[@Include]", namespaceManager);

            if (hasNunitReference == null)
                return false;

            foreach (XmlNode reference in hasNunitReference)
            {
                if (reference.Attributes != null)
                {
                    var value = reference.Attributes["Include"].Value.ToUpper();

                    if (value.StartsWith("NUNIT.FRAMEWORK"))
                        return true;
                }
            }

            return false;
        }