Пример #1
0
        private async Task <ProjectFileInfo> BuildProjectFileInfoAsync(CancellationToken cancellationToken)
        {
            var project = await _buildManager.BuildProjectAsync(_loadedProject, Log, cancellationToken).ConfigureAwait(false);

            return(project != null
                ? CreateProjectFileInfo(project)
                : ProjectFileInfo.CreateEmpty(Language, _loadedProject.FullPath, Log));
        }
Пример #2
0
        public async Task <ImmutableArray <ProjectFileInfo> > GetProjectFileInfosAsync(CancellationToken cancellationToken)
        {
            if (_loadedProject is null)
            {
                return(ImmutableArray.Create(ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath, Log)));
            }

            var targetFrameworkValue  = _loadedProject.GetPropertyValue(PropertyNames.TargetFramework);
            var targetFrameworksValue = _loadedProject.GetPropertyValue(PropertyNames.TargetFrameworks);

            if (RoslynString.IsNullOrEmpty(targetFrameworkValue) && !RoslynString.IsNullOrEmpty(targetFrameworksValue))
            {
                // This project has a <TargetFrameworks> property, but does not specify a <TargetFramework>.
                // In this case, we need to iterate through the <TargetFrameworks>, set <TargetFramework> with
                // each value, and build the project.

                var targetFrameworks = targetFrameworksValue.Split(';');
                var results          = ImmutableArray.CreateBuilder <ProjectFileInfo>(targetFrameworks.Length);

                if (!_loadedProject.GlobalProperties.TryGetValue(PropertyNames.TargetFramework, out var initialGlobalTargetFrameworkValue))
                {
                    initialGlobalTargetFrameworkValue = null;
                }

                foreach (var targetFramework in targetFrameworks)
                {
                    _loadedProject.SetGlobalProperty(PropertyNames.TargetFramework, targetFramework);
                    _loadedProject.ReevaluateIfNecessary();

                    var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false);

                    results.Add(projectFileInfo);
                }

                if (initialGlobalTargetFrameworkValue is null)
                {
                    _loadedProject.RemoveGlobalProperty(PropertyNames.TargetFramework);
                }
                else
                {
                    _loadedProject.SetGlobalProperty(PropertyNames.TargetFramework, initialGlobalTargetFrameworkValue);
                }

                _loadedProject.ReevaluateIfNecessary();

                return(results.ToImmutable());
            }
            else
            {
                var projectFileInfo = await BuildProjectFileInfoAsync(cancellationToken).ConfigureAwait(false);

                projectFileInfo ??= ProjectFileInfo.CreateEmpty(Language, _loadedProject?.FullPath, Log);
                return(ImmutableArray.Create(projectFileInfo));
            }
        }
Пример #3
0
            private async Task <ImmutableArray <ProjectFileInfo> > LoadProjectFileInfosAsync(string projectPath, DiagnosticReportingOptions reportingOptions, CancellationToken cancellationToken)
            {
                if (!_projectFileLoaderRegistry.TryGetLoaderFromProjectPath(projectPath, reportingOptions.OnLoaderFailure, out var loader))
                {
                    return(ImmutableArray <ProjectFileInfo> .Empty); // Failure should already be reported.
                }

                var projectFile = await DoOperationAndReportProgressAsync(
                    ProjectLoadOperation.Evaluate,
                    projectPath,
                    targetFramework : null,
                    () => loader.LoadProjectFileAsync(projectPath, _buildManager, cancellationToken)
                    ).ConfigureAwait(false);

                // If there were any failures during load, we won't be able to build the project. So, bail early with an empty project.
                if (projectFile.Log.HasFailure)
                {
                    _diagnosticReporter.Report(projectFile.Log);

                    return(ImmutableArray.Create(
                               ProjectFileInfo.CreateEmpty(loader.Language, projectPath, projectFile.Log)));
                }

                var projectFileInfos = await DoOperationAndReportProgressAsync(
                    ProjectLoadOperation.Build,
                    projectPath,
                    targetFramework : null,
                    () => projectFile.GetProjectFileInfosAsync(cancellationToken)
                    ).ConfigureAwait(false);

                var results = ImmutableArray.CreateBuilder <ProjectFileInfo>(projectFileInfos.Length);

                foreach (var projectFileInfo in projectFileInfos)
                {
                    // If any diagnostics were logged during build, we'll carry on and try to produce a meaningful project.
                    if (!projectFileInfo.Log.IsEmpty)
                    {
                        _diagnosticReporter.Report(projectFileInfo.Log);
                    }

                    results.Add(projectFileInfo);
                }

                return(results.MoveToImmutable());
            }