-
Notifications
You must be signed in to change notification settings - Fork 391
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Recreate ApplicationPropertyPage in code. #7922
Draft
tmeschter
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
tmeschter:220216-AppPropPageInCode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
257 changes: 257 additions & 0 deletions
257
...Studio.ProjectSystem.Managed/ProjectSystem/Rules/PropertyPages/ApplicationPropertyPage.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,257 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. The .NET Foundation licenses this file to you under the MIT license. See the LICENSE.md file in the project root for more information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Microsoft.Build.Framework.XamlTypes; | ||
using Microsoft.VisualStudio.ProjectSystem.Properties; | ||
using PPR = Microsoft.VisualStudio.ProjectSystem.Rules.PropertyPages.PropertyPageResources; | ||
|
||
namespace Microsoft.VisualStudio.ProjectSystem.Rules.PropertyPages | ||
{ | ||
internal static class PropertyMetadata | ||
{ | ||
public static readonly string VisibilityCondition = "VisibilityCondition"; | ||
public static readonly string SearchTerms = "SearchTerms"; | ||
public static readonly string DependsOn = "DependsOn"; | ||
} | ||
|
||
// TODO: The context could come from a constant. | ||
[ExportRuleObjectProvider(name: "DefaultApplicationPropertyPageProvider", context: "Project")] | ||
[AppliesTo(ProjectCapability.CSharpOrVisualBasicOrFSharp)] | ||
[Order(Order.Default)] | ||
internal sealed class ApplicationPropertyPageProvider : IRuleObjectProvider | ||
{ | ||
private const string GeneralCategoryName = "General"; | ||
private const string ResourcesCategoryName = "Resources"; | ||
private const string PackagingCategoryName = "Packaging"; | ||
|
||
private readonly Lazy<List<Rule>> _rules = new(CreateRules); | ||
|
||
private static List<Rule> CreateRules() | ||
{ | ||
Rule rule = new(); | ||
|
||
rule.BeginInit(); | ||
|
||
rule.Name = "Application"; | ||
rule.Description = PPR.ApplicationPage_Description; | ||
rule.DisplayName = PPR.ApplicationPage_DisplayName; | ||
// TODO: The PageTemplate could come from a constant. | ||
rule.PageTemplate = "generic"; | ||
rule.Order = 100; | ||
|
||
rule.Categories = new() | ||
{ | ||
CreateCategory( | ||
name: GeneralCategoryName, | ||
displayName: PPR.ApplicationPage_GeneralCategory_DisplayName, | ||
description: PPR.ApplicationPage_GeneralCategory_Description), | ||
CreateCategory( | ||
name: ResourcesCategoryName, | ||
displayName: PPR.ApplicationPage_ResourcesCategory_DisplayName, | ||
description: PPR.ApplicationPage_ResourcesCategory_Description), | ||
CreateCategory( | ||
name: PackagingCategoryName, | ||
displayName: PPR.ApplicationPage_PackagingCategory_DisplayName, | ||
description: PPR.ApplicationPage_PackagingCategory_Description) | ||
}; | ||
|
||
rule.DataSource = new() | ||
{ | ||
// TODO: The Persistence could come from a constant. | ||
Persistence = "ProjectFile", | ||
SourceOfDefaultValue = DefaultValueSourceLocation.AfterContext, | ||
HasConfigurationCondition = false | ||
}; | ||
|
||
EnumProperty outputTypeProperty = new() | ||
{ | ||
Name = "OutputType", | ||
DisplayName = PPR.ApplicationPage_OutputTypeProperty_DisplayName, | ||
Description = PPR.ApplicationPage_OutputTypeProperty_Description, | ||
Category = GeneralCategoryName, | ||
AdmissibleValues = | ||
{ | ||
new() { Name = "Library", DisplayName = PPR.ApplicationPage_OutputTypeProperty_LibraryValue_DisplayName }, | ||
new() { Name = "Exe", DisplayName = PPR.ApplicationPage_OutputTypeProperty_ExeValue_DisplayName }, | ||
new() { Name = "WinExe", DisplayName = PPR.ApplicationPage_OutputTypeProperty_WinExeValue_DisplayName } | ||
} | ||
}; | ||
|
||
BoolProperty targetMultipleFrameworksProperty = new() | ||
{ | ||
Name = "TargetMultipleFrameworks", | ||
DisplayName = PPR.ApplicationPage_TargetMultipleFrameworksProperty_DisplayName, | ||
Description = PPR.ApplicationPage_TargetMultipleFrameworksProperty_Description, | ||
HelpUrl = "https://go.microsoft.com/fwlink/?linkid=2147236", | ||
Category = GeneralCategoryName, | ||
Visible = false, | ||
DataSource = new() | ||
{ | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
} | ||
}; | ||
|
||
DynamicEnumProperty interceptedTargetFrameworkProperty = new() | ||
{ | ||
Name = "InterceptedTargetFramework", | ||
DisplayName = PPR.ApplicationPage_InterceptedTargetFrameworkProperty_DisplayName, | ||
Description = PPR.ApplicationPage_InterceptedTargetFrameworkProperty_Description, | ||
HelpUrl = "https://go.microsoft.com/fwlink/?linkid=2147236", | ||
Category = GeneralCategoryName, | ||
EnumProvider = "SupportedTargetFrameworksEnumProvider", | ||
MultipleValuesAllowed = false, | ||
DataSource = new() | ||
{ | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
}, | ||
Metadata = | ||
{ | ||
new() { Name = PropertyMetadata.VisibilityCondition, Value = "(not (has-evaluated-value \"Application\" \"TargetMultipleFrameworks\" true))" }, | ||
new() { Name = PropertyMetadata.SearchTerms, Value = PPR.ApplicationPage_InterceptedTargetFrameworkProperty_SearchTerms }, | ||
new() { Name = PropertyMetadata.DependsOn, Value = "Application::TargetMultipleFrameworks" } | ||
} | ||
}; | ||
|
||
StringProperty targetFrameworksProperty = new() | ||
{ | ||
Name = "TargetFrameworks", | ||
DisplayName = PPR.ApplicationPage_TargetFrameworksProperty_DisplayName, | ||
Description = PPR.ApplicationPage_TargetFrameworksProperty_Description, | ||
HelpUrl = "https://go.microsoft.com/fwlink/?linkid=2147236", | ||
Category = GeneralCategoryName, | ||
DataSource = new() | ||
{ | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
}, | ||
Metadata = | ||
{ | ||
new() { Name = PropertyMetadata.VisibilityCondition, Value = "(has-evaluated-value \"Application\" \"TargetMultipleFrameworks\" true)" }, | ||
new() { Name = PropertyMetadata.SearchTerms, Value = PPR.ApplicationPage_TargetFrameworksProperty_SearchTerms }, | ||
new() { Name = PropertyMetadata.DependsOn, Value = "Application::TargetMultipleFrameworks" } | ||
} | ||
}; | ||
|
||
StringProperty installOtherFrameworksProperty = new() | ||
{ | ||
Name = "InstallOtherFrameworks", | ||
DisplayName = PPR.ApplicationPage_InstallOtherFrameworksProperty_DisplayName, | ||
Category = GeneralCategoryName, | ||
DataSource = new() | ||
{ | ||
PersistedName = "InstallOtherFrameworks", | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
}, | ||
ValueEditors = | ||
{ | ||
new() | ||
{ | ||
// TODO: EditorType could come from a constant | ||
EditorType = "LinkAction", | ||
Metadata = | ||
{ | ||
new() { Name = "Action", Value = "URL" }, | ||
new() { Name = "URL", Value = "http://go.microsoft.com/fwlink/?LinkID=287120" } | ||
} | ||
} | ||
} | ||
}; | ||
|
||
DynamicEnumProperty targetPlatformIdentifierProperty = new() | ||
{ | ||
Name = "TargetPlatformIdentifier", | ||
DisplayName = PPR.ApplicationPage_TargetPlatformIdentifierProperty_DisplayName, | ||
Description = PPR.ApplicationPage_TargetPlatformIdentifierProperty_Description, | ||
Category = GeneralCategoryName, | ||
EnumProvider = "SdkSupportedTargetPlatformIdentifierEnumProvider", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These could be constants on the provider classes. |
||
HelpUrl = "https://go.microsoft.com/fwlink/?linkid=2184943", | ||
DataSource = new() | ||
{ | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
}, | ||
Metadata = new() | ||
{ | ||
new() { Name = PropertyMetadata.SearchTerms, Value = PPR.ApplicationPage_TargetPlatformIdentifierProperty_SearchTerms }, | ||
new() | ||
{ | ||
Name = PropertyMetadata.VisibilityCondition, | ||
Value = @" | ||
(and | ||
(has-net-core-app-version-or-greater ""5.0"") | ||
(not (has-evaluated-value ""Application"" ""TargetMultipleFrameworks"" true))) | ||
" | ||
} | ||
} | ||
}; | ||
|
||
DynamicEnumProperty targetPlatformVersionProperty = new() | ||
{ | ||
Name = "TargetPlatformVersion", | ||
DisplayName = PPR.ApplicationPage_TargetPlatformVersionProperty_DisplayName, | ||
Description = PPR.ApplicationPage_TargetPlatformVersionProperty_Description, | ||
Category = GeneralCategoryName, | ||
EnumProvider = "SdkSupportedTargetPlatformVersionEnumProvider", | ||
HelpUrl = "https://go.microsoft.com/fwlink/?linkid=2185153", | ||
DataSource = new() | ||
{ | ||
Persistence = "ProjectFileWithInterception", | ||
HasConfigurationCondition = false | ||
}, | ||
Metadata = new() | ||
{ | ||
new() | ||
{ | ||
Name = PropertyMetadata.VisibilityCondition, | ||
Value = | ||
@" | ||
(and | ||
(has-net-core-app-version-or-greater ""5.0"") | ||
(and | ||
(ne (unevaluated ""Application"" ""TargetPlatformIdentifier"") """") | ||
(not (has-evaluated-value ""Application"" ""TargetMultipleFrameworks"" true)))) | ||
" | ||
}, | ||
new() { Name = PropertyMetadata.SearchTerms, Value = PPR.ApplicationPage_TargetPlatformVersionProperty_SearchTerms }, | ||
new() { Name = PropertyMetadata.DependsOn, Value = "Application::TargetPlatformIdentifier" } | ||
} | ||
}; | ||
|
||
rule.Properties = new() | ||
{ | ||
outputTypeProperty, | ||
targetMultipleFrameworksProperty, | ||
interceptedTargetFrameworkProperty, | ||
targetFrameworksProperty, | ||
installOtherFrameworksProperty, | ||
targetPlatformIdentifierProperty, | ||
targetPlatformVersionProperty, | ||
|
||
}; | ||
|
||
rule.EndInit(); | ||
|
||
List<Rule> rules = new(); | ||
rules.Add(rule); | ||
|
||
return rules; | ||
} | ||
|
||
private static Category CreateCategory(string name, string displayName, string description) | ||
{ | ||
Category category = new(); | ||
category.BeginInit(); | ||
category.Name = name; | ||
category.DisplayName = displayName; | ||
category.Description = description; | ||
category.EndInit(); | ||
return category; | ||
} | ||
|
||
public IReadOnlyCollection<Rule> GetRules() => _rules.Value; | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some helper methods for this kind of thing could be helpful.
This could be written as: