/// <summary> /// <see cref="IActiveDebugFrameworkServices.GetConfiguredProjectForActiveFrameworkAsync"/> /// </summary> public async Task <ConfiguredProject> GetConfiguredProjectForActiveFrameworkAsync() { var configProjects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync().ConfigureAwait(false); // If there is only one we are done if (configProjects.Count == 1) { return(configProjects.First().Value); } var activeFramework = await GetActiveDebuggingFrameworkPropertyAsync().ConfigureAwait(false); if (!string.IsNullOrWhiteSpace(activeFramework)) { if (configProjects.TryGetValue(activeFramework, out ConfiguredProject configuredProject)) { return(configuredProject); } } // We can't just select the first one. If activeFramework is not set we must pick the first one as defined by the // targetFrameworks property. So we need the order as returned by GetProjectFrameworks() var frameworks = await GetProjectFrameworksAsync().ConfigureAwait(false); if (frameworks != null && frameworks.Count > 0) { if (configProjects.TryGetValue(frameworks[0], out ConfiguredProject configuredProject)) { return(configuredProject); } } // All that is left is to return the first one. return(configProjects.First().Value); }
private async Task <AggregateCrossTargetProjectContext> CreateProjectContextAsyncCore() { // Don't initialize until the project has been loaded into the IDE and available in Solution Explorer await _asyncLoadDashboard.ProjectLoadedInHostWithCancellation(_commonServices.Project).ConfigureAwait(false); return(await _taskScheduler.RunAsync(TaskSchedulerPriority.UIThreadBackgroundPriority, async() => { var projectData = GetProjectData(); // Get the set of active configured projects ignoring target framework. #pragma warning disable CS0618 // Type or member is obsolete var configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync().ConfigureAwait(true); #pragma warning restore CS0618 // Type or member is obsolete var activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; var innerProjectContextsBuilder = ImmutableDictionary.CreateBuilder <ITargetFramework, ITargetedProjectContext>(); var activeTargetFramework = TargetFramework.Empty; foreach (var kvp in configuredProjectsMap) { var configuredProject = kvp.Value; var projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>(); var configurationGeneralProperties = await projectProperties.GetConfigurationGeneralPropertiesAsync().ConfigureAwait(true); var targetFramework = await GetTargetFrameworkAsync(kvp.Key, configurationGeneralProperties).ConfigureAwait(false); if (!TryGetConfiguredProjectState(configuredProject, out ITargetedProjectContext targetedProjectContext)) { // Get the target path for the configured project. var targetPath = (string)await configurationGeneralProperties.TargetPath.GetValueAsync().ConfigureAwait(true); var displayName = GetDisplayName(configuredProject, projectData, targetFramework.FullName); targetedProjectContext = new TargetedProjectContext(targetFramework, projectData.FullPath, displayName, targetPath) { // By default, set "LastDesignTimeBuildSucceeded = false" until first design time // build succeeds for this project. LastDesignTimeBuildSucceeded = false }; AddConfiguredProjectState(configuredProject, targetedProjectContext); } innerProjectContextsBuilder.Add(targetFramework, targetedProjectContext); if (activeTargetFramework.Equals(TargetFramework.Empty) && configuredProject.ProjectConfiguration.Equals(activeProjectConfiguration)) { activeTargetFramework = targetFramework; } } var isCrossTargeting = !(configuredProjectsMap.Count == 1 && string.IsNullOrEmpty(configuredProjectsMap.First().Key)); return new AggregateCrossTargetProjectContext(isCrossTargeting, innerProjectContextsBuilder.ToImmutable(), configuredProjectsMap, activeTargetFramework, _targetFrameworkProvider); }));
/// <summary> /// <see cref="IActiveDebugFrameworkServices.GetConfiguredProjectForActiveFrameworkAsync"/> /// </summary> public async Task <ConfiguredProject?> GetConfiguredProjectForActiveFrameworkAsync() { #pragma warning disable CS0618 // Type or member is obsolete ImmutableDictionary <string, ConfiguredProject>?configProjects = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); #pragma warning restore CS0618 // Type or member is obsolete if (configProjects == null) { return(null); } // If there is only one we are done if (configProjects.Count == 1) { return(configProjects.First().Value); } string?activeFramework = await GetActiveDebuggingFrameworkPropertyAsync(); if (!Strings.IsNullOrWhiteSpace(activeFramework)) { if (configProjects.TryGetValue(activeFramework, out ConfiguredProject? configuredProject)) { return(configuredProject); } } // We can't just select the first one. If activeFramework is not set we must pick the first one as defined by the // targetFrameworks property. So we need the order as returned by GetProjectFrameworks() List <string>?frameworks = await GetProjectFrameworksAsync(); if (frameworks?.Count > 0) { if (configProjects.TryGetValue(frameworks[0], out ConfiguredProject? configuredProject)) { return(configuredProject); } } // All that is left is to return the first one. return(configProjects.First().Value); }
public async Task <AggregateCrossTargetProjectContext> CreateProjectContextAsync() { // Get the set of active configured projects ignoring target framework. #pragma warning disable CS0618 // Type or member is obsolete ImmutableDictionary <string, ConfiguredProject> configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); #pragma warning restore CS0618 // Type or member is obsolete ProjectConfiguration activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; ImmutableArray <ITargetFramework> .Builder targetFrameworks = ImmutableArray.CreateBuilder <ITargetFramework>(initialCapacity: configuredProjectsMap.Count); ITargetFramework activeTargetFramework = TargetFramework.Empty; foreach ((string tfm, ConfiguredProject configuredProject) in configuredProjectsMap) { ProjectProperties projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>(); ConfigurationGeneral configurationGeneralProperties = await projectProperties.GetConfigurationGeneralPropertiesAsync(); ITargetFramework targetFramework = await GetTargetFrameworkAsync(tfm, configurationGeneralProperties); targetFrameworks.Add(targetFramework); if (activeTargetFramework.Equals(TargetFramework.Empty) && configuredProject.ProjectConfiguration.Equals(activeProjectConfiguration)) { activeTargetFramework = targetFramework; } } bool isCrossTargeting = !(configuredProjectsMap.Count == 1 && string.IsNullOrEmpty(configuredProjectsMap.First().Key)); return(new AggregateCrossTargetProjectContext( isCrossTargeting, targetFrameworks.MoveToImmutable(), configuredProjectsMap, activeTargetFramework, _targetFrameworkProvider)); }
private async Task <AggregateWorkspaceProjectContext> CreateProjectContextAsyncCore() { string languageName = await GetLanguageServiceName().ConfigureAwait(false); if (string.IsNullOrEmpty(languageName)) { return(null); } Guid projectGuid = await GetProjectGuidAsync().ConfigureAwait(false); string targetPath = await GetTargetPathAsync().ConfigureAwait(false); if (string.IsNullOrEmpty(targetPath)) { return(null); } // Don't initialize until the project has been loaded into the IDE and available in Solution Explorer await _asyncLoadDashboard.ProjectLoadedInHostWithCancellation(_commonServices.Project).ConfigureAwait(false); // TODO: https://github.com/dotnet/roslyn-project-system/issues/353 return(await _taskScheduler.RunAsync(TaskSchedulerPriority.UIThreadBackgroundPriority, async() => { await _commonServices.ThreadingService.SwitchToUIThread(); var projectData = GetProjectData(); // Get the set of active configured projects ignoring target framework. #pragma warning disable CS0618 // Type or member is obsolete var configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync().ConfigureAwait(true); #pragma warning restore CS0618 // Type or member is obsolete // Get the unconfigured project host object (shared host object). var configuredProjectsToRemove = new HashSet <ConfiguredProject>(_configuredProjectHostObjectsMap.Keys); var activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; var innerProjectContextsBuilder = ImmutableDictionary.CreateBuilder <string, IWorkspaceProjectContext>(); string activeTargetFramework = string.Empty; IConfiguredProjectHostObject activeIntellisenseProjectHostObject = null; foreach (var kvp in configuredProjectsMap) { var targetFramework = kvp.Key; var configuredProject = kvp.Value; if (!TryGetConfiguredProjectState(configuredProject, out IWorkspaceProjectContext workspaceProjectContext, out IConfiguredProjectHostObject configuredProjectHostObject)) { // Get the target path for the configured project. var projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>(); var configurationGeneralProperties = await projectProperties.GetConfigurationGeneralPropertiesAsync().ConfigureAwait(true); targetPath = (string)await configurationGeneralProperties.TargetPath.GetValueAsync().ConfigureAwait(true); var targetFrameworkMoniker = (string)await configurationGeneralProperties.TargetFrameworkMoniker.GetValueAsync().ConfigureAwait(true); var displayName = GetDisplayName(configuredProject, projectData, targetFramework); configuredProjectHostObject = _projectHostProvider.GetConfiguredProjectHostObject(_unconfiguredProjectHostObject, displayName, targetFrameworkMoniker); // TODO: https://github.com/dotnet/roslyn-project-system/issues/353 await _commonServices.ThreadingService.SwitchToUIThread(); workspaceProjectContext = _contextFactory.Value.CreateProjectContext(languageName, displayName, projectData.FullPath, projectGuid, configuredProjectHostObject, targetPath); // By default, set "LastDesignTimeBuildSucceeded = false" to turn off diagnostics until first design time build succeeds for this project. workspaceProjectContext.LastDesignTimeBuildSucceeded = false; AddConfiguredProjectState(configuredProject, workspaceProjectContext, configuredProjectHostObject); } innerProjectContextsBuilder.Add(targetFramework, workspaceProjectContext); if (activeIntellisenseProjectHostObject == null && configuredProject.ProjectConfiguration.Equals(activeProjectConfiguration)) { activeIntellisenseProjectHostObject = configuredProjectHostObject; activeTargetFramework = targetFramework; } } _unconfiguredProjectHostObject.ActiveIntellisenseProjectHostObject = activeIntellisenseProjectHostObject; return new AggregateWorkspaceProjectContext(innerProjectContextsBuilder.ToImmutable(), configuredProjectsMap, activeTargetFramework, _unconfiguredProjectHostObject); }));
/// <summary> /// Creates a <see cref="AggregateCrossTargetProjectContext"/>. /// </summary> /// <returns> /// The created <see cref="AggregateCrossTargetProjectContext"/>. /// </returns> public async Task <AggregateCrossTargetProjectContext> CreateProjectContextAsync() { // Get the set of active configured projects ignoring target framework. #pragma warning disable CS0618 // Type or member is obsolete ImmutableDictionary <string, ConfiguredProject>?configuredProjectsMap = await _activeConfiguredProjectsProvider.GetActiveConfiguredProjectsMapAsync(); #pragma warning restore CS0618 // Type or member is obsolete if (configuredProjectsMap == null) { throw new InvalidOperationException("There are no active configured projects."); } ProjectConfiguration activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration; ImmutableArray <TargetFramework> .Builder targetFrameworks = ImmutableArray.CreateBuilder <TargetFramework>(initialCapacity: configuredProjectsMap.Count); TargetFramework activeTargetFramework = TargetFramework.Empty; foreach ((string tfm, ConfiguredProject configuredProject) in configuredProjectsMap) { TargetFramework targetFramework = await GetTargetFrameworkAsync(tfm, configuredProject); targetFrameworks.Add(targetFramework); if (activeTargetFramework.Equals(TargetFramework.Empty) && configuredProject.ProjectConfiguration.Equals(activeProjectConfiguration)) { activeTargetFramework = targetFramework; } } bool isCrossTargeting = !(configuredProjectsMap.Count == 1 && string.IsNullOrEmpty(configuredProjectsMap.First().Key)); return(new AggregateCrossTargetProjectContext( isCrossTargeting, targetFrameworks.MoveToImmutable(), configuredProjectsMap, activeTargetFramework, _targetFrameworkProvider)); }