コード例 #1
0
        internal MSBuildProjectLoader(
            HostWorkspaceServices workspaceServices,
            DiagnosticReporter diagnosticReporter,
            ProjectFileLoaderRegistry projectFileLoaderRegistry,
            ImmutableDictionary <string, string> properties)
        {
            _workspaceServices         = workspaceServices;
            _diagnosticReporter        = diagnosticReporter;
            _pathResolver              = new PathResolver(_diagnosticReporter);
            _projectFileLoaderRegistry = projectFileLoaderRegistry ?? new ProjectFileLoaderRegistry(workspaceServices, _diagnosticReporter);

            _properties = ImmutableDictionary.Create <string, string>(StringComparer.OrdinalIgnoreCase);

            if (properties != null)
            {
                _properties = _properties.AddRange(properties);
            }
        }
            public static bool TryRead(string filterFilename, PathResolver pathResolver, out string solutionFilename, out ImmutableHashSet <string> projectFilter)
            {
                try
                {
                    using var document = JsonDocument.Parse(File.ReadAllText(filterFilename));
                    var solution     = document.RootElement.GetProperty("solution");
                    var solutionPath = solution.GetProperty("path").GetString();

                    if (!pathResolver.TryGetAbsoluteSolutionPath(solutionPath, baseDirectory: Path.GetDirectoryName(filterFilename), DiagnosticReportingMode.Throw, out solutionFilename))
                    {
                        // TryGetAbsoluteSolutionPath should throw before we get here.
                        solutionFilename = string.Empty;
                        projectFilter    = ImmutableHashSet <string> .Empty;
                        return(false);
                    }

                    if (!File.Exists(solutionFilename))
                    {
                        projectFilter = ImmutableHashSet <string> .Empty;
                        return(false);
                    }

                    var filterProjects = ImmutableHashSet.CreateBuilder <string>(StringComparer.OrdinalIgnoreCase);
                    foreach (var project in solution.GetProperty("projects").EnumerateArray())
                    {
                        var projectPath = project.GetString();
                        if (projectPath is null)
                        {
                            continue;
                        }

                        filterProjects.Add(projectPath);
                    }

                    projectFilter = filterProjects.ToImmutable();
                    return(true);
                }
                catch
                {
                    solutionFilename = string.Empty;
                    projectFilter    = ImmutableHashSet <string> .Empty;
                    return(false);
                }
            }
コード例 #3
0
 public Worker(
     HostWorkspaceServices services,
     DiagnosticReporter diagnosticReporter,
     PathResolver pathResolver,
     ProjectFileLoaderRegistry projectFileLoaderRegistry,
     ProjectBuildManager buildManager,
     ImmutableArray <string> requestedProjectPaths,
     string baseDirectory,
     ImmutableDictionary <string, string> globalProperties,
     ProjectMap?projectMap,
     IProgress <ProjectLoadProgress>?progress,
     DiagnosticReportingOptions requestedProjectOptions,
     DiagnosticReportingOptions discoveredProjectOptions,
     bool preferMetadataForReferencesOfDiscoveredProjects
     )
 {
     _workspaceServices         = services;
     _diagnosticReporter        = diagnosticReporter;
     _pathResolver              = pathResolver;
     _projectFileLoaderRegistry = projectFileLoaderRegistry;
     _buildManager              = buildManager;
     _baseDirectory             = baseDirectory;
     _requestedProjectPaths     = requestedProjectPaths;
     _globalProperties          = globalProperties;
     _projectMap = projectMap ?? ProjectMap.Create();
     _progress   = progress;
     _requestedProjectOptions  = requestedProjectOptions;
     _discoveredProjectOptions = discoveredProjectOptions;
     _preferMetadataForReferencesOfDiscoveredProjects =
         preferMetadataForReferencesOfDiscoveredProjects;
     _projectIdToFileInfoMap          = new Dictionary <ProjectId, ProjectFileInfo>();
     _pathToDiscoveredProjectInfosMap = new Dictionary <
         string,
         ImmutableArray <ProjectInfo>
         >(PathUtilities.Comparer);
     _projectIdToProjectReferencesMap =
         new Dictionary <ProjectId, List <ProjectReference> >();
 }
コード例 #4
0
            public static bool TryRead(
                string filterFilename,
                PathResolver pathResolver,
                [NotNullWhen(true)] out string?solutionFilename,
                out ImmutableHashSet <string> projectFilter
                )
            {
                try
                {
                    using var document = JsonDocument.Parse(File.ReadAllText(filterFilename));
                    var solution = document.RootElement.GetProperty("solution");
                    // Convert directory separators to the platform's default, since that is what MSBuild provide us.
                    var solutionPath = solution
                                       .GetProperty("path")
                                       .GetString()
                                       ?.Replace('\\', Path.DirectorySeparatorChar);
                    if (
                        solutionPath is null ||
                        Path.GetDirectoryName(filterFilename) is not string baseDirectory
                        )
                    {
                        solutionFilename = string.Empty;
                        projectFilter    = ImmutableHashSet <string> .Empty;
                        return(false);
                    }

                    if (
                        !pathResolver.TryGetAbsoluteSolutionPath(
                            solutionPath,
                            baseDirectory,
                            DiagnosticReportingMode.Throw,
                            out solutionFilename
                            )
                        )
                    {
                        // TryGetAbsoluteSolutionPath should throw before we get here.
                        solutionFilename = string.Empty;
                        projectFilter    = ImmutableHashSet <string> .Empty;
                        return(false);
                    }

                    if (!File.Exists(solutionFilename))
                    {
                        projectFilter = ImmutableHashSet <string> .Empty;
                        return(false);
                    }

                    // The base directory for projects is the solution folder.
                    baseDirectory = Path.GetDirectoryName(solutionFilename) !;
                    RoslynDebug.AssertNotNull(baseDirectory);

                    var filterProjects = ImmutableHashSet.CreateBuilder <string>(
                        StringComparer.OrdinalIgnoreCase
                        );
                    foreach (var project in solution.GetProperty("projects").EnumerateArray())
                    {
                        // Convert directory separators to the platform's default, since that is what MSBuild provide us.
                        var projectPath = project
                                          .GetString()
                                          ?.Replace('\\', Path.DirectorySeparatorChar);
                        if (projectPath is null)
                        {
                            continue;
                        }

                        // Fill the filter with the absolute project paths.
                        if (
                            pathResolver.TryGetAbsoluteProjectPath(
                                projectPath,
                                baseDirectory,
                                DiagnosticReportingMode.Throw,
                                out var absoluteProjectPath
                                )
                            )
                        {
                            filterProjects.Add(absoluteProjectPath);
                        }
                    }

                    projectFilter = filterProjects.ToImmutable();
                    return(true);
                }
                catch
                {
                    solutionFilename = string.Empty;
                    projectFilter    = ImmutableHashSet <string> .Empty;
                    return(false);
                }
            }