コード例 #1
0
        /// <summary>
        /// Removes a platform from the project.
        /// </summary>
        /// <param name="project">Unconfigured project for which the configuration change.</param>
        /// <param name="platformName">Name of the deleted platform.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnPlatformDeletedAsync(UnconfiguredProject project, string platformName)
        {
            string evaluatedPropertyValue = await GetPropertyValue(project);

            await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject =>
            {
                BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName);
            });
        }
コード例 #2
0
        /// <summary>
        /// Removes a platform from the project.
        /// </summary>
        /// <param name="unconfiguredProject">Unconfigured project for which the configuration change.</param>
        /// <param name="platformName">Name of the deleted platform.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnPlatformDeletedAsync(UnconfiguredProject unconfiguredProject, string platformName)
        {
            string evaluatedPropertyValue = await GetPropertyValue(unconfiguredProject).ConfigureAwait(false);

            await ProjectXmlAccessor.ExecuteInWriteLock(msbuildProject =>
            {
                BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName);
            }).ConfigureAwait(false);
        }
コード例 #3
0
        /// <summary>
        /// Removes a configuration from the project.
        /// </summary>
        /// <param name="project">Unconfigured project for which the configuration change.</param>
        /// <param name="configurationName">Name of the deleted configuration.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnConfigurationRemovedAsync(UnconfiguredProject project, string configurationName)
        {
            string evaluatedPropertyValue = await GetPropertyValue(project).ConfigureAwait(false);

            await ProjectXmlAccessor.ExecuteInWriteLock(msbuildProject =>
            {
                BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, configurationName);
            }).ConfigureAwait(false);
        }
コード例 #4
0
        /// <summary>
        /// Modifies the project when there's a configuration change.
        /// </summary>
        /// <param name="args">Information about the configuration dimension value change.</param>
        /// <returns>A task for the async operation.</returns>
        public Task OnDimensionValueChangedAsync(ProjectConfigurationDimensionValueChangedEventArgs args)
        {
            if (StringComparers.ConfigurationDimensionNames.Equals(args.DimensionName, DimensionName))
            {
                if (args.Stage == ChangeEventStage.Before)
                {
                    switch (args.Change)
                    {
                    case ConfigurationDimensionChange.Add:
                        return(UpdateUnderLockAsync(args.Project, (msbuildProject, evaluatedPropertyValue) =>
                                                    BuildUtilities.AppendPropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, args.DimensionValue)));

                    case ConfigurationDimensionChange.Delete:
                        return(UpdateUnderLockAsync(args.Project, (msbuildProject, evaluatedPropertyValue) =>
                                                    BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, args.DimensionValue)));

                    case ConfigurationDimensionChange.Rename:
                        // Need to wait until the core rename changes happen before renaming the property.
                        break;
                    }
                }
                else if (args.Stage == ChangeEventStage.After)
                {
                    // Only change that needs to be handled here is renaming configurations which needs to happen after all
                    // of the core changes to rename existing conditions have executed.
                    if (args.Change == ConfigurationDimensionChange.Rename)
                    {
                        return(UpdateUnderLockAsync(args.Project, (msbuildProject, evaluatedPropertyValue) =>
                                                    BuildUtilities.RenamePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, args.OldDimensionValue, args.DimensionValue)));
                    }
                }
            }

            return(Task.CompletedTask);

            async Task UpdateUnderLockAsync(UnconfiguredProject project, Action <ProjectRootElement, string> action)
            {
                ConfiguredProject?configuredProject = await project.GetSuggestedConfiguredProjectAsync();

                Assumes.NotNull(configuredProject);

                await ProjectAccessor.OpenProjectForUpgradeableReadAsync(configuredProject, evaluatedProject =>
                {
                    string evaluatedPropertyValue = evaluatedProject.GetPropertyValue(PropertyName);

                    return(ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject =>
                    {
                        action(msbuildProject, evaluatedPropertyValue);
                    }));
                });
            }
        }
コード例 #5
0
        /// <summary>
        /// Removes a platform from the project.
        /// </summary>
        /// <param name="project">Unconfigured project for which the configuration change.</param>
        /// <param name="platformName">Name of the deleted platform.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnPlatformDeletedAsync(UnconfiguredProject project, string platformName)
        {
            string?evaluatedPropertyValue = await GetPropertyValue(project);

            if (evaluatedPropertyValue == null)
            {
                throw new InvalidOperationException($"Property {PropertyName} not defined.");
            }
            await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject =>
            {
                BuildUtilities.RemovePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName);
            });
        }