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

PublishAot deployment ignores call to Application.SetHighDpiMode #11543

Open
OwnageIsMagic opened this issue Jun 17, 2024 · 9 comments
Open

PublishAot deployment ignores call to Application.SetHighDpiMode #11543

OwnageIsMagic opened this issue Jun 17, 2024 · 9 comments
Labels
area-HDPI HDPI, not specific to Dpi mode of app area-ILLinker/AOT
Milestone

Comments

@OwnageIsMagic
Copy link

OwnageIsMagic commented Jun 17, 2024

.NET version

.NET SDK:
Version: 9.0.100-preview.5.24307.3
Commit: 35b2c21ea6
Workload version: 9.0.100-manifests.6407b7e4
MSBuild version: 17.11.0-preview-24279-02+b963c24ef

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win-x64

Microsoft.WindowsDesktop.App 9.0.0-preview.5.24306.8

Did it work in any of the earlier releases of .NET Core or .NET 5+?

No response

Issue description

dotnet publish
image
dotnet run or publish with <dpiAware /> in manifest
image
but specifying dpi awareness in manifest results in warning CSC : warning WFAC010: Remove high DPI settings from C:\Source\ttt\app.manifest and configure via Application.SetHighDpiMode API or 'ApplicationHighDpiMode' project property
Display settings
image

Steps to reproduce

mkdir ttt && cd ttt && dotnet new winforms
Form1.cs

namespace ttt;

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();

	var cb = new CheckBox();

	cb.Location = new Point(3, 73);
	cb.Size = new Size(152, 29);
	cb.Text = "Always on top";
	cb.UseVisualStyleBackColor = true;

	Controls.Add(cb);
    }
}

ttt.csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net9.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <UseWindowsForms>true</UseWindowsForms>
    <ImplicitUsings>enable</ImplicitUsings>

    <!-- uncomment to fix -->
    <!-- <ApplicationManifest>app.manifest</ApplicationManifest> -->

    <PublishAot>true</PublishAot>
    <_SuppressWinFormsTrimError>true</_SuppressWinFormsTrimError>

  </PropertyGroup>

</Project>

app.manifest

<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">

  <assemblyIdentity type="win32" version="1.0.0.0" name="my.app"/>

  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
    <security>
      <requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
        <requestedExecutionLevel level="asInvoker" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>

  <application xmlns="urn:schemas-microsoft-com:asm.v3">
    <windowsSettings>
      <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true</dpiAware>
      <!-- <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2,permonitor,system</dpiAwareness> -->
    </windowsSettings>
  </application>

</assembly>
@OwnageIsMagic OwnageIsMagic added the untriaged The team needs to look at this issue in the next triage label Jun 17, 2024
@elachlan elachlan added area-ILLinker/AOT area-HDPI HDPI, not specific to Dpi mode of app labels Jun 18, 2024
@elachlan
Copy link
Contributor

elachlan commented Jun 18, 2024

So you followed the warning and commented out dpiAwareness from the manifest and configured the dpi settings via Application.SetHighDpiMode API or ApplicationHighDpiMode project property?

Do you have a copy of your program.cs?

@OwnageIsMagic
Copy link
Author

OwnageIsMagic commented Jun 18, 2024

@elachlan actually the other way around. App was looking strange in aot mode, so I tried to enable dpi awareness via manifest, it worked, but produced warning.
Program.cs is default one generated by dotnet new winforms.
I verified that ApplicationConfiguration.Initialize(); contains global::System.Windows.Forms.Application.SetHighDpiMode(HighDpiMode.SystemAware);
All code here is the full repro.

@elachlan
Copy link
Contributor

@Olina-Zhang can your team please verify?

@OwnageIsMagic
Copy link
Author

Screen capture

Animation

@Olina-Zhang
Copy link
Member

@Olina-Zhang can your team please verify?

We can repro it in the latest .NET 9.0 Preview6 SDK build with PublishAot deployment.

@chrarnoldus
Copy link

Is it related to this? #9911 (comment)

@OwnageIsMagic
Copy link
Author

OwnageIsMagic commented Jun 18, 2024

@chrarnoldus dpiAware=true is equivalent to dpiAwareness=system and SystemAware is default for netcore winforms and wpf (as mentioned in comment)
So using system is ok.
And yes, it's probably related to initialization order.

@merriemcgaw merriemcgaw added this to the .NET 10.0 milestone Jun 18, 2024
@merriemcgaw merriemcgaw removed the untriaged The team needs to look at this issue in the next triage label Jun 18, 2024
@KlausLoeffelmann
Copy link
Member

KlausLoeffelmann commented Jun 18, 2024

If you don't do this via the project settings, but have the code manually added in Program.cs to control HighDPI settings and other settings, does that then change anything?

Also not, that Trimming/AOTing WinForms Apps is not supported at this time, but we're working on it.

@OwnageIsMagic
Copy link
Author

OwnageIsMagic commented Jun 18, 2024

@KlausLoeffelmann adding this doesn't resolve the issue.

static Program()
{
    Application.SetHighDpiMode(HighDpiMode.SystemAware);
}
[System.Runtime.CompilerServices.ModuleInitializer]
internal static void M1()
{
    Application.SetHighDpiMode(HighDpiMode.SystemAware);
}

Huh, "supported" winforms trimming looks like this error NETSDK1175: Windows Forms is not supported or recommended with trimming enabled. Please go to https://aka.ms/dotnet-illink/windows-forms for more details..😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-HDPI HDPI, not specific to Dpi mode of app area-ILLinker/AOT
Projects
None yet
Development

No branches or pull requests

6 participants