Ejemplo n.º 1
0
        /// <summary>
        /// Gets the property values for the dimension.
        /// </summary>
        /// <param name="project">Unconfigured project.</param>
        /// <returns>Collection of values for the dimension.</returns>
        /// <remarks>
        /// From <see cref="IProjectConfigurationDimensionsProvider"/>.
        /// </remarks>
        private async Task <ImmutableArray <string> > GetOrderedPropertyValuesAsync(UnconfiguredProject project)
        {
            Requires.NotNull(project, nameof(project));

            string?propertyValue = await GetPropertyValueAsync(project);

            if (Strings.IsNullOrEmpty(propertyValue))
            {
                return(ImmutableArray <string> .Empty);
            }
            else
            {
                return(BuildUtilities.GetPropertyValues(propertyValue).ToImmutableArray());
            }

            async Task <string?> GetPropertyValueAsync(UnconfiguredProject project)
            {
                ConfiguredProject?configuredProject = await project.GetSuggestedConfiguredProjectAsync();

                Assumes.NotNull(configuredProject);

                return(await ProjectAccessor.OpenProjectForReadAsync(configuredProject, evaluatedProject =>
                {
                    // Need evaluated property to get inherited properties defines in props or targets.
                    return evaluatedProject.GetProperty(PropertyName)?.EvaluatedValue;
                }));
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Returns true if this cross-targeting aggregate project context has the same set of target frameworks and active target framework as the given TargetFrameworks property value.
        /// </summary>
        /// <param name="targetFrameworksProperty">Property value for MSBuild property "TargetsFramework"</param>
        public bool HasMatchingTargetFrameworks(string targetFrameworksProperty)
        {
            Requires.NotNull(targetFrameworksProperty, nameof(targetFrameworksProperty));
            Requires.Range(IsCrossTargeting, nameof(targetFrameworksProperty), "This method should only be invoked for Cross targeting projects");

            ImmutableArray <string> parsedTargetFrameworks = BuildUtilities.GetPropertyValues(targetFrameworksProperty);

            if (parsedTargetFrameworks.Length != _configuredProjectContextsByTargetFramework.Count)
            {
                // Different number of target frameworks.
                return(false);
            }

            if (!_activeTargetFramework.Equals(parsedTargetFrameworks[0]))
            {
                // Active target framework is different.
                return(false);
            }

            foreach (var targetFrameworkMoniker in parsedTargetFrameworks.Skip(1))
            {
                var targetFramework = TargetFrameworkProvider.GetTargetFramework(targetFrameworkMoniker);
                if (!_configuredProjectContextsByTargetFramework.ContainsKey(targetFramework))
                {
                    // Differing TargetFramework
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// <see cref="IActiveDebugFrameworkServices.GetProjectFrameworksAsync"/>
        /// </summary>
        public async Task <List <string> > GetProjectFrameworksAsync()
        {
            // It is important that we return the frameworks in the order they are specified in the project to ensure the default is set
            // correctly.
            ConfigurationGeneral props = await _commonProjectServices.ActiveConfiguredProjectProperties.GetConfigurationGeneralPropertiesAsync().ConfigureAwait(false);

            string targetFrameworks = (string)await props.TargetFrameworks.GetValueAsync().ConfigureAwait(false);

            if (!string.IsNullOrWhiteSpace(targetFrameworks))
            {
                return(BuildUtilities.GetPropertyValues(targetFrameworks).ToList());
            }
            return(null);
        }
        /// <summary>
        /// Gets the property values for the dimension.
        /// </summary>
        /// <param name="project">Unconfigured project.</param>
        /// <returns>Collection of values for the dimension.</returns>
        /// <remarks>
        /// From <see cref="IProjectConfigurationDimensionsProvider"/>.
        /// </remarks>
        protected virtual async Task <ImmutableArray <string> > GetOrderedPropertyValuesAsync(UnconfiguredProject project)
        {
            Requires.NotNull(project, nameof(project));

            string propertyValue = await GetPropertyValue(project);

            if (propertyValue == null || string.IsNullOrEmpty(propertyValue))
            {
                return(ImmutableArray <string> .Empty);
            }
            else
            {
                return(BuildUtilities.GetPropertyValues(propertyValue));
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Gets the property values for the dimension.
        /// </summary>
        /// <param name="project"><see cref="Project"/>.</param>
        /// <returns>Collection of values for the dimension.</returns>
        private ImmutableArray <string> GetOrderedPropertyValues(Project project)
        {
            Requires.NotNull(project, nameof(project));

            string?propertyValue = project.GetProperty(PropertyName)?.EvaluatedValue;

            if (Strings.IsNullOrEmpty(propertyValue))
            {
                return(ImmutableArray <string> .Empty);
            }
            else
            {
                return(BuildUtilities.GetPropertyValues(propertyValue).ToImmutableArray());
            }
        }
Ejemplo n.º 6
0
        protected override async Task <ImmutableArray <string> > GetOrderedPropertyValuesAsync(UnconfiguredProject project)
        {
            Requires.NotNull(project, nameof(project));

            string targetFrameworksProperty = await GetPropertyValue(project, ConfigurationGeneral.TargetFrameworksProperty);

            if (targetFrameworksProperty != null)
            {
                return(BuildUtilities.GetPropertyValues(targetFrameworksProperty).ToImmutableArray());
            }
            else
            {
                // If the project doesn't have a "TargetFrameworks" property, then this is not a cross-targeting project and we don't need a target framework dimension.
                return(ImmutableArray <string> .Empty);
            }
        }
Ejemplo n.º 7
0
        protected override async Task <ImmutableArray <string> > GetOrderedPropertyValuesAsync(UnconfiguredProject project)
        {
            Requires.NotNull(project, nameof(project));

            string targetFrameworkProperty = await _projectXmlAccessor.GetEvaluatedPropertyValue(project, ConfigurationGeneral.TargetFrameworkProperty).ConfigureAwait(true);

            if (targetFrameworkProperty != null)
            {
                // If the project already defines a specific "TargetFramework" to target, then this is not a cross-targeting project and we don't need a target framework dimension.
                return(ImmutableArray <string> .Empty);
            }
            else
            {
                string targetFrameworksProperty = await _projectXmlAccessor.GetEvaluatedPropertyValue(project, ConfigurationGeneral.TargetFrameworksProperty).ConfigureAwait(true);

                return(BuildUtilities.GetPropertyValues(targetFrameworksProperty));
            }
        }
        private async Task <string> FindDefaultValueFromDimensionPropertyAsync(UnconfiguredProject project)
        {
            string values = await FindDimensionPropertyAsync(project);

            if (string.IsNullOrEmpty(values))
            {
                return(null);
            }

            foreach (string defaultValue in BuildUtilities.GetPropertyValues(values))
            {
                // If this property is derived from another property, skip it and just
                // pull default from next known values. This is better than picking a
                // default that is not actually one of the known configs.
                if (defaultValue.IndexOf("$(") == -1)
                {
                    return(defaultValue);
                }
            }

            return(null);
        }