Esempio n. 1
0
        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);
            }));
        private async Task <AggregateCrossTargetProjectContext> CreateProjectContextAsyncCore()
        {
            ProjectData projectData = GetProjectData();

            // 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().ConfigureAwait(true);

#pragma warning restore CS0618 // Type or member is obsolete
            ProjectConfiguration activeProjectConfiguration = _commonServices.ActiveConfiguredProject.ProjectConfiguration;
            ImmutableDictionary <ITargetFramework, ITargetedProjectContext> .Builder innerProjectContextsBuilder = ImmutableDictionary.CreateBuilder <ITargetFramework, ITargetedProjectContext>();
            ITargetFramework activeTargetFramework = TargetFramework.Empty;

            foreach (KeyValuePair <string, ConfiguredProject> kvp in configuredProjectsMap)
            {
                ConfiguredProject    configuredProject = kvp.Value;
                ProjectProperties    projectProperties = configuredProject.Services.ExportProvider.GetExportedValue <ProjectProperties>();
                ConfigurationGeneral configurationGeneralProperties = await projectProperties.GetConfigurationGeneralPropertiesAsync().ConfigureAwait(true);

                ITargetFramework targetFramework = await GetTargetFrameworkAsync(kvp.Key, configurationGeneralProperties).ConfigureAwait(false);

                if (!TryGetConfiguredProjectState(configuredProject, out ITargetedProjectContext targetedProjectContext))
                {
                    // Get the target path for the configured project.
                    string targetPath = (string)await configurationGeneralProperties.TargetPath.GetValueAsync().ConfigureAwait(true);

                    string 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;
                }
            }

            bool isCrossTargeting = !(configuredProjectsMap.Count == 1 && string.IsNullOrEmpty(configuredProjectsMap.First().Key));
            return(new AggregateCrossTargetProjectContext(isCrossTargeting,
                                                          innerProjectContextsBuilder.ToImmutable(),
                                                          configuredProjectsMap,
                                                          activeTargetFramework,
                                                          _targetFrameworkProvider));
        }