/// <summary> /// Renames an existing configuration in the project. /// </summary> /// <param name="project">Unconfigured project for which the configuration change.</param> /// <param name="oldName">Original name of the configuration.</param> /// <param name="newName">New name of the configuration.</param> /// <returns>A task for the async operation.</returns> private async Task OnConfigurationRenamedAsync(UnconfiguredProject project, string oldName, string newName) { string evaluatedPropertyValue = await GetPropertyValue(project); await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.RenamePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, oldName, newName); }); }
/// <summary> /// Renames an existing configuration in the project. /// </summary> /// <param name="unconfiguredProject">Unconfigured project for which the configuration change.</param> /// <param name="oldName">Original name of the configuration.</param> /// <param name="newName">New name of the configuration.</param> /// <returns>A task for the async operation.</returns> private async Task OnConfigurationRenamedAsync(UnconfiguredProject unconfiguredProject, string oldName, string newName) { string evaluatedPropertyValue = await GetPropertyValue(unconfiguredProject).ConfigureAwait(false); await ProjectXmlAccessor.ExecuteInWriteLock(msbuildProject => { BuildUtilities.RenamePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, oldName, newName); }).ConfigureAwait(false); }
/// <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); })); }); } }
/// <summary> /// Renames an existing configuration in the project. /// </summary> /// <param name="project">Unconfigured project for which the configuration change.</param> /// <param name="oldName">Original name of the configuration.</param> /// <param name="newName">New name of the configuration.</param> /// <returns>A task for the async operation.</returns> private async Task OnConfigurationRenamedAsync(UnconfiguredProject project, string oldName, string newName) { string?evaluatedPropertyValue = await GetPropertyValue(project); if (evaluatedPropertyValue == null) { throw new InvalidOperationException($"Property {PropertyName} not defined."); } await ProjectAccessor.OpenProjectXmlForWriteAsync(project, msbuildProject => { BuildUtilities.RenamePropertyValue(msbuildProject, evaluatedPropertyValue, PropertyName, oldName, newName); }); }