示例#1
0
        public ProjectSource Parse()
        {
            var project = new ProjectSource(_projectName, _filePath);

            Parse(project);
            return(project);
        }
示例#2
0
 public void Parse(ProjectSource projectSource)
 {
     projectSource.References.Add("mscorlib");
     projectSource.References.AddRange(ParseReferences());
     projectSource.ProjectReferences.AddRange(ParseProjectReferences());
     projectSource.Documents.AddRange(ParseCompileItems());
 }
示例#3
0
 private static void ReadDocuments(ProjectSource projectSource, Project project)
 {
     foreach (var document in project.Documents.Where(d => d.SupportsSemanticModel))
     {
         if (!string.IsNullOrWhiteSpace(document.FilePath))
         {
             projectSource.Documents.Add(new DocumentSource(document.Name, document.FilePath));
         }
     }
 }
示例#4
0
 private static void ReadReferences(ProjectSource projectSource, Project project)
 {
     foreach (var metadataReference in project.MetadataReferences.OfType <PortableExecutableReference>())
     {
         if (!string.IsNullOrWhiteSpace(metadataReference.FilePath))
         {
             projectSource.References.Add(metadataReference.FilePath);
         }
     }
 }
示例#5
0
        public async Task ParseAsync(ProjectSource projectSource)
        {
            var workspace = MSBuildWorkspace.Create();
            var project   = await workspace.OpenProjectAsync(projectSource.Path);

            ReadDocuments(projectSource, project);

            ReadReferences(projectSource, project);

            ReadProjectReferences(projectSource, project, workspace);
        }
示例#6
0
 private static void ReadProjectReferences(ProjectSource projectSource, Project project, MSBuildWorkspace workspace)
 {
     foreach (var projectReference in project.ProjectReferences)
     {
         var reffedProject = workspace.CurrentSolution.GetProject(projectReference.ProjectId);
         if (!(reffedProject?.FilePath is null))
         {
             projectSource.ProjectReferences.Add(reffedProject.FilePath);
         }
     }
 }
        public async Task <bool> LoadAsync(ProjectSource projectSource)
        {
            if (!_fileSystem.File.Exists(projectSource.Path))
            {
                return(false);
            }

            var text = await _fileSystem.File.ReadAllTextAsync(projectSource.Path);

            await ParseAsync(projectSource, text);

            return(true);
        }
        private static async Task <ProjectSource> ParseAsync(ProjectSource projectSource, string text)
        {
            var xml = XDocument.Parse(text);

            if (xml.Root?.Attribute("xmlns")?.Value is string)
            {
                OldStyleProjectParser.Create(xml.Root, projectSource.Path).Parse(projectSource);
                return(projectSource);
            }

            var newStyleProjectParser = new NewStyleProjectParser();
            await newStyleProjectParser.ParseAsync(projectSource);

            return(projectSource);
        }
        public bool TryParseLine(ReadOnlySpan <char> line, [NotNullWhen(true)] out ProjectSource?project)
        {
            project = null;

            if (!TrySkipPastChar(ref line, '='))
            {
                return(false);
            }

            if (!TryGetNextQuotedString(ref line, out var projectName))
            {
                return(false);
            }

            if (!TryGetNextQuotedString(ref line, out var projectFilePath))
            {
                return(false);
            }

            project = new ProjectSource(projectName, Path.GetFullPath(projectFilePath, _solutionDirectory));
            return(true);
        }
        private ProjectInfo CreateProjectInfo(ProjectSource projectSource)
        {
            var projectId = ProjectId.CreateNewId();

            var projectReferences = projectSource.ProjectReferences
                                    .Select(TryGetProjectReference)
                                    .WhereNotNull();

            var metadataReferences = projectSource.References
                                     .Select(TryGetMetadataReference)
                                     .WhereNotNull();

            var documents = projectSource.Documents
                            .Select(d => CreateDocumentInfo(projectId, d))
                            .WhereNotNull();

            return(ProjectInfo.Create(projectId, VersionStamp.Default, projectSource.Name, projectSource.Name, LanguageNames.CSharp,
                                      projectSource.Path,
                                      projectReferences: projectReferences,
                                      metadataReferences: metadataReferences,
                                      documents: documents));
        }