dotnet / project-system

The .NET Project System for Visual Studio
MIT License
968 stars 387 forks source link

Add ApplicationHighDpiMode property to project file. #8980

Open melytc opened 1 year ago

melytc commented 1 year ago

Summary

WinForms Designer is currently working on improving the HighDPI settings experience for .NET Core apps. For C#, they are reading the project file to get the property that a user manually edited. For VB, we currently save all Application Framework properties to the myapp file; however, the WinForms Designer doesn't have access to it. The request is to save that property both in the myapp file as well as the project file.

myapp: <HighDpiMode>0</HighDpiMode>

vbproj: <ApplicationHighDpiMode>SystemAware</ApplicationHighDpiMode>

The source of truth would still be the myapp file; this is mainly to unblock the WinForms Designer team.

melytc commented 1 year ago

@KlausLoeffelmann just to confirm, the value saved in the project file does not need to be converted to int, right?

We currently save this property as an int in the myapp file, but I noticed your email had the string value. 0 -> DpiUnaware 1 -> SystemAware 2 -> PerMonitor 3 -> PerMonitorV2 4 -> DpiUnawareGdiScaled

drewnoakes commented 1 year ago

I would be concerned that if the value is in both the .myapp and the .vbproj that users could rightfully think that editing the MSBuild property should make a difference to the application, but it in fact will not.

How is the designer reading these properties? If they're read through the .NET Project System, we can create "fake" properties for these values that are exposed via interception. Would that work? In that way there's still only one source of truth.

For C# projects, where there's no .myapp file, I suppose we would continue to write to the project file only.

melytc commented 1 year ago

That's a valid concern; we would want to be clear to the user that manually editing the vbproj would cause them to be out of sync via documentation. However, I like the idea of surfacing it through a pseudo-property. @KlausLoeffelmann would that work for you?

For C# projects, where there's no .myapp file, I suppose we would continue to write to the project file only.

That's right, this only involves VB as it has that property in the myapp file, and the Designer has no way of reading it. For C# they are reading the csproj directly.

drewnoakes commented 1 year ago

I don't think documentation would help much in practice. If we can not write it into the .vbproj file, I think that'd be ideal.

KlausLoeffelmann commented 1 year ago

If they're read through the .NET Project System, we can create "fake" properties for these values that are exposed via interception. Would that work? In that way there's still only one source of truth.

We've planned as the longer-term approach to migrate the application.myapp file to VBProj altogether, so I want to be mindful with the resources, and only have a quick solution at this time, since we got a couple of requests already, that the WinForms Out-Of-Proc Designer picks up settings for C# but not for VB. However, if this interception approach is not too much of an additional workload, I would gladly take it of course! 😸

I am not so much concerned about this setting not getting picked up by MSBuild, since also application.myapp is not getting picked up by MSBuild (which is one of the reasons we want to migrate to VBProj; the required codegen is (historically) only working in Visual Studio (when application.myapp is actually being written) - and doesn't work anywhere else.

@dreddy-work: What's the exact technical approach to get the settings read from the cs/vbproj file?

dreddy-work commented 1 year ago

What's the exact technical approach to get the settings read from the cs/vbproj file?

We read properties via IVsBuildPropertyStorage.GetPropertyValue() API.

We currently save this property as an int in the myapp file, but I noticed your email had the string value

Its Enum and we parse them to convert either way here. So either notion should work (string is preferred).

We would prefer to keep both the projfile and myappfile synchronized, provided that it does not require excessive effort. However, considering that there are discussions about replacing MyApp with the project file, I am not insistent on this. My understanding is, it should be fairly straight to keep them in sync if users are editing the MyApp file within Visual Studio and in the project, but any editing done outside of Visual Studio/project should not be considered at this time.

drewnoakes commented 1 year ago

We read properties via IVsBuildPropertyStorage.GetPropertyValue() API

I would hope that property interception would mean we could have the values only in the .myapp file and never in the project file. I think this is possible, and worth investigating.