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

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

            await ProjectXmlAccessor.ExecuteInWriteLock(msbuildProject =>
            {
                BuildUtilities.AppendPropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName);
            }).ConfigureAwait(false);
        }
        /// <summary>
        /// Adds a configuration to the project.
        /// </summary>
        /// <param name="project">Unconfigured project for which the configuration change.</param>
        /// <param name="configurationName">Name of the new configuration.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnConfigurationAddedAsync(UnconfiguredProject project, string configurationName)
        {
            string evaluatedPropertyValue = await GetPropertyValue(project).ConfigureAwait(false);

            await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject =>
            {
                BuildUtilities.AppendPropertyValue(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>
        /// Adds a platform to the project.
        /// </summary>
        /// <param name="project">Unconfigured project for which the configuration change.</param>
        /// <param name="platformName">Name of the new platform.</param>
        /// <returns>A task for the async operation.</returns>
        private async Task OnPlatformAddedAsync(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.AppendPropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, platformName);
            });
        }