diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/ApplicationPropertyPage/ApplicationFrameworkValueProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/ApplicationPropertyPage/ApplicationFrameworkValueProvider.cs index e59c2d3bf6c..80f8c110f88 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/ApplicationPropertyPage/ApplicationFrameworkValueProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Properties/InterceptedProjectProperties/ApplicationPropertyPage/ApplicationFrameworkValueProvider.cs @@ -30,7 +30,6 @@ internal sealed class ApplicationFrameworkValueProvider : InterceptingPropertyVa private const string WinExeOutputType = "WinExe"; private const string NoneItemType = "None"; private const string ApplicationDefinitionItemType = "ApplicationDefinition"; - private const string ApplicationFileName = "Application.xaml"; private readonly UnconfiguredProject _project; private readonly IProjectItemProvider _sourceItemsProvider; @@ -52,7 +51,7 @@ public ApplicationFrameworkValueProvider( public override async Task OnSetPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties, IReadOnlyDictionary? dimensionalConditions = null) { - if (propertyName == ApplicationFramework) + if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework)) { if (await IsWPFApplicationAsync(defaultProperties)) { @@ -71,7 +70,7 @@ public ApplicationFrameworkValueProvider( public override Task OnGetEvaluatedPropertyValueAsync(string propertyName, string evaluatedPropertyValue, IProjectProperties defaultProperties) { - if (propertyName == ApplicationFramework) + if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework)) { return GetPropertyValueAsync(defaultProperties); } @@ -83,7 +82,7 @@ public override Task OnGetEvaluatedPropertyValueAsync(string propertyNam public override Task OnGetUnevaluatedPropertyValueAsync(string propertyName, string unevaluatedPropertyValue, IProjectProperties defaultProperties) { - if (propertyName == ApplicationFramework) + if (StringComparers.PropertyNames.Equals(propertyName, ApplicationFramework)) { return GetPropertyValueAsync(defaultProperties); } @@ -170,10 +169,11 @@ private async Task IsWPFApplicationAsync(IProjectProperties defaultPropert if (startupObjectValue is not null) { + string prefix = rootNamespace + "."; // Use StringComparison.OrdinalIgnoreCase because VB is _not_ case-sensitive - if (startupObjectValue.StartsWith(rootNamespace + ".", StringComparison.OrdinalIgnoreCase)) + if (startupObjectValue.StartsWith(prefix, StringComparison.OrdinalIgnoreCase)) { - startupObjectValue = startupObjectValue.Substring((rootNamespace + ".").Length); + startupObjectValue = startupObjectValue.Substring(prefix.Length); } await _myAppXmlFileAccessor.SetMainFormAsync(startupObjectValue); } @@ -212,18 +212,21 @@ private async Task IsWPFApplicationAsync(IProjectProperties defaultPropert { // Enabled + string? appXamlFileName = Path.GetFileName(await GetAppXamlRelativeFilePathAsync(create: false)); + // Project accessor to remove the ApplicationDefinition property if re-enabled + // Note: this code causes CPS tree validation warning in Debug builds only, but we are ignorning await _projectAccessor.OpenProjectXmlForWriteAsync(_project, project => { - foreach (ProjectItemGroupElement itemGroup in project.ItemGroups.ToList()) + foreach (ProjectItemGroupElement itemGroup in project.ItemGroups) { foreach (ProjectItemElement item in itemGroup.Items.ToList()) { - if (string.Equals(item.ItemType, ApplicationDefinitionItemType, StringComparisons.ItemTypes)) + if (StringComparers.ItemTypes.Equals(item.ItemType, ApplicationDefinitionItemType)) { itemGroup.RemoveChild(item); } - else if (string.Equals(item.ItemType, NoneItemType, StringComparisons.ItemTypes) && string.Equals(item.Include, ApplicationFileName, StringComparison.Ordinal)) + else if (StringComparers.ItemTypes.Equals(item.ItemType, NoneItemType) && StringComparers.Paths.Equals(item.Include, appXamlFileName)) { itemGroup.RemoveChild(item); }