Skip to content
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

Save startup object correctly; show correct dropdown entries. #9300

Merged
merged 2 commits into from
Oct 26, 2023

Conversation

melytc
Copy link
Contributor

@melytc melytc commented Oct 26, 2023

Fixes #9262

  • Don't show an entry for 'My.MyApplication' value. That is only set in the project file but should not be surfaced to the UI. Value should come from the myapp file.
  • Show correct StartupObject property. Seems like we had 2 properties, one in the base Application.xaml rule and another in the vb-specific Application.xaml rule. Ensured that they have different names and have a visibility condition that would show/hide the correct one, depending on the project language. Interceptor had the wrong property name InterceptedStartupObjectProperty; it now uses the correct property name.

The only thing missing is to ensure the VB WinForms template contains the correct value in the StartupObject: right now it has 'Sub Main', but should be '[rootnamespace].My.MyApplication'.

Microsoft Reviewers: Open in CodeFlow

- Don't show an entry for 'My.MyApplication' value. That is only set in the project file but should not be surfaced to the UI. Value should come from the myapp file.
- Show correct StartupObject property. Seems like we had 2 properties, one in the base Application.xaml rule and another in the vb-specific Application.xaml rule. Ensured that they have different names and have a visibility condition that would show/hide the correct one, depending on the project language.
The only thing missing is to ensure the VB WinForms template contains the correct value in the StartupObject: right now it has 'Sub Main', but should be '[rootnamespace].My.MyApplication'.
@melytc melytc requested a review from a team as a code owner October 26, 2023 01:02
@ghost ghost added Feature-Project-Properties-Designer The new project property pages which replace the legacy AppDesigner Feature-WinForms Features related to bringing up the Windows Forms designer and related features. labels Oct 26, 2023
@melytc
Copy link
Contributor Author

melytc commented Oct 26, 2023

@melytc
Copy link
Contributor Author

melytc commented Oct 26, 2023

just noticed Klaus is OOF; @merriemcgaw, do you know if that's the case? 🙂

@KlausLoeffelmann
Copy link
Member

@@ -94,6 +94,9 @@ public async Task<ICollection<IEnumValue>> GetListedValuesAsync()
}));
}

// Remove My.MyApplication entry if any.
enumValues = enumValues.Where(ep => !ep.Name.Contains("My.MyApplication")).ToList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this code runs for C# too. It seems unlikely that would ever be an issue.

This can also be slightly more efficient if you use List.RemoveAll:

Suggested change
enumValues = enumValues.Where(ep => !ep.Name.Contains("My.MyApplication")).ToList();
enumValues.RemoveAll(ep => !ep.Name.Contains("My.MyApplication"));

It's more efficient because it doesn't allocate a new list, and if nothing matches the predicate then no memory is modified at all, whereas the previous code would always create a full copy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this code runs for C# too. It seems unlikely that would ever be an issue.

That's what I thought too, this value only makes sense in VB projects. These entries come from IEntryPointFinderService from Roslyn; it might be the case that we need to make the change there instead of here, but I'm not sure.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's definitely worth investigating whether the filtering should live on the Roslyn side. Ideally we don't get involved in these kinds of language level policies.

Copy link
Member

@KlausLoeffelmann KlausLoeffelmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me also, so far.
Just one thing to keep in mind in the context of the templates:
Most of projects out there do have "Sub Main" currently as the start object setting. So, while I of course agree that we should change the template, if there is a Sub Main, but the Application Framework is enabled, we need to "migrate" the setting to something meaningfull, and work with the assumption, that if ApplicationFramework is enabled, then application.myapp is the source of truth, and we update the start object in vbproj on the next opportunity.

Avoid allocating a new list by using List.RemoveAll.
There's no need to have different properties: the VB-specific file replaces the base one and it is only included for VB projects, so we can also remove the visibility condition.
Unfortunately, this reverts the changes that caused the localization files to change but doesn't reset their status to translated.
@melytc
Copy link
Contributor Author

melytc commented Oct 26, 2023

So, while I of course agree that we should change the template, if there is a Sub Main, but the Application Framework is enabled, we need to "migrate" the setting to something meaningfull, and work with the assumption, that if ApplicationFramework is enabled, then application.myapp is the source of truth, and we update the start object in vbproj on the next opportunity.

That's a good point. I have tested this scenario and we will handle this correctly:

Here's a new VB WinForms:
image

The selected startup object is Form1, and that's the only valid entry point.
image

Adding a second form and selecting that in the UI would cause these changes:
image

That would ensure the project file gets the correct value if the startup object is changed, as well as ensure the value is saved in the myapp file since the application framework property is enabled. 🙂

@melytc melytc merged commit d5b40e9 into dotnet:main Oct 26, 2023
5 checks passed
@melytc melytc deleted the startupobject-fix branch October 26, 2023 21:47
@ghost ghost added this to the 17.9 milestone Oct 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature-Project-Properties-Designer The new project property pages which replace the legacy AppDesigner Feature-WinForms Features related to bringing up the Windows Forms designer and related features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

StartupObject is saved in project file instead of myapp file.
4 participants