Visual Studio 2017中Enable DPI Awareness设置无效求助
Let’s tackle this step by step—since you’ve already tried the project config toggle and manual edits get overwritten, here are actionable fixes to get your DPI awareness settings stuck in the auto-generated manifest:
1. Lock Down Project Manifest Merging Settings
First, make sure Visual Studio isn’t ignoring your custom manifest:
- Right-click your project → Properties → go to Configuration Properties > Manifest Tool > Input and Output
- Set Additional Manifest Files to point directly to your custom manifest file (e.g.,
$(ProjectDir)app.manifest) - Set Merge Manifests to Yes (/MANIFEST:MERGE)
- Set Additional Manifest Files to point directly to your custom manifest file (e.g.,
- Head to Configuration Properties > Linker > Manifest File
- Confirm Generate Manifest is set to Yes (/MANIFEST)
- Double-check Additional Manifest Files matches the path above
2. Block Auto-Injected DPI Awareness Code
Visual Studio sometimes automatically adds default DPI awareness flags that can conflict with your custom manifest. Stop this by adding a compiler macro:
- Go to Configuration Properties > C/C++ > Command Line
- In the Additional Options box, add:
/D "_DISABLE_DPI_AWARENESS"
This prevents the compiler from injecting its own DPI-related manifest elements.
3. Write a Complete DPI-Aware Manifest
Make sure your custom manifest includes the correct DPI awareness nodes—here’s a working template (pick the one that fits your needs):
<?xml version='1.0' encoding='UTF-8' standalone='yes'?> <assembly xmlns='urn:schemas-microsoft-com:asm.v1' manifestVersion='1.0'> <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3"> <security> <requestedPrivileges> <requestedExecutionLevel level='asInvoker' uiAccess='false' /> </requestedPrivileges> </security> </trustInfo> <application xmlns="urn:schemas-microsoft-com:asm.v3"> <windowsSettings> <!-- For system DPI awareness or per-monitor v1 --> <dpiAware xmlns="http://schemas.microsoft.com/SMI/2005/WindowsSettings">true/PM</dpiAware> <!-- Uncomment below for per-monitor v2 (recommended for modern apps) --> <!-- <dpiAwareness xmlns="http://schemas.microsoft.com/SMI/2016/WindowsSettings">PerMonitorV2, PerMonitor</dpiAwareness> --> </windowsSettings> </application> </assembly>
- Add this file to your project, then right-click the manifest file → Properties
- Set Item Type to Manifest Tool Input to ensure it’s included in the build process.
4. Clean Up Build Caches
Old cached manifest files often cause headaches. Do a full clean and reset:
- Delete the
Debug/Releaseoutput folders - Delete the hidden
.vsfolder in your project root (this clears VS’s build cache) - Rebuild the project from scratch
For CMake Users (If Applicable)
If you’re using CMake instead of VS project files, add these lines to your CMakeLists.txt to force your custom manifest:
set_target_properties(YourProjectName PROPERTIES WIN32_EXECUTABLE YES MANIFEST_INPUT ${CMAKE_SOURCE_DIR}/path/to/your/manifest.manifest )
After following these steps, your built manifest should include the DPI awareness tags without needing any programmatic setup.
内容的提问来源于stack exchange,提问作者FelixH

