@@ -22,7 +22,7 @@ internal enum ProjectOptionGenerationLevel
2222 All ,
2323 }
2424
25- public class ProjectOptionsGenerator
25+ public partial class ProjectOptionsGenerator
2626 {
2727 // Only MacOS have a subfolder, refer to https://developer.apple.com/library/archive/documentation/CoreFoundation/Conceptual/CFBundles/BundleTypes/BundleTypes.html
2828 private static readonly string AppleAppBinaryRootFolderForMac = "Contents" + XCodeProj . FolderSeparator + "MacOS" + XCodeProj . FolderSeparator ;
@@ -1948,37 +1948,64 @@ private void GenerateManifestToolOptions(IGenerationContext context, ProjectOpti
19481948
19491949 Strings manifestInputs = new Strings ( ) ;
19501950
1951- string vsManifestFilesPath = Util . SimplifyPath ( Path . Combine ( context . DevelopmentEnvironment . GetVisualStudioVCRootPath ( ) , "Include" , "Manifest" ) ) ;
1951+ bool generateManifestFile = false ;
19521952
19531953 //EnableDpiAwareness
1954+ // Yes and PerMonitor both map to the same value, since dpi scaling really doesn't work well in windows 10+ without PerMonitorV2 specified.
1955+ // This should be safe for older versions too, according to msdn documentation (see link below): "On older versions of Windows, the newer <dpiAwareness> tag will be ignored."
1956+ // https://learn.microsoft.com/en-us/windows/win32/hidpi/setting-the-default-dpi-awareness-for-a-process#setting-default-awareness-with-the-application-manifest
19541957 context . SelectOption
19551958 (
19561959 Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . Default , ( ) => { context . Options [ "EnableDpiAwareness" ] = FileGeneratorUtilities . RemoveLineTag ; } ) ,
1957- Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . Yes , ( ) => { context . Options [ "EnableDpiAwareness" ] = "true " ; manifestInputs . Add ( Path . Combine ( vsManifestFilesPath , "dpiaware.manifest" ) ) ; } ) ,
1958- Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . PerMonitor , ( ) => { context . Options [ "EnableDpiAwareness" ] = "PerMonitorHighDPIAware" ; manifestInputs . Add ( Path . Combine ( vsManifestFilesPath , "PerMonitorHighDPIAware.manifest" ) ) ; } ) ,
1960+ Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . Yes , ( ) => { context . Options [ "EnableDpiAwareness" ] = "PerMonitorHighDPIAware " ; generateManifestFile = true ; } ) ,
1961+ Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . PerMonitor , ( ) => { context . Options [ "EnableDpiAwareness" ] = "PerMonitorHighDPIAware" ; generateManifestFile = true ; } ) ,
19591962 Options . Option ( Options . Vc . ManifestTool . EnableDpiAwareness . No , ( ) => { context . Options [ "EnableDpiAwareness" ] = "false" ; } )
19601963 ) ;
19611964
1962- if ( context . Configuration . AdditionalManifestFiles . Count > 0 )
1965+ if ( generateManifestFile )
19631966 {
1964- context . Options [ "AdditionalManifestFiles" ] = string . Join ( ";" , Util . PathGetRelative ( context . ProjectDirectory , context . Configuration . AdditionalManifestFiles ) ) ;
1965- manifestInputs . AddRange ( context . Configuration . AdditionalManifestFiles ) ;
1967+ var fileGenerator = new XmlFileGenerator ( ) ;
1968+ fileGenerator . Write ( Template . Manifest . FileBegin ) ;
1969+ fileGenerator . Write ( Template . Manifest . DPIAwarenessSettings ) ;
1970+ fileGenerator . Write ( Template . Manifest . FileEnd ) ;
1971+
1972+ string projFilePath = context . Configuration . ProjectFullFileName ;
1973+ projFilePath = projFilePath . Replace ( '.' , '_' ) ;
1974+
1975+ FileInfo projectFileInfo = new FileInfo ( projFilePath + ".manifest" ) ;
1976+ context . Builder . Context . WriteGeneratedFile ( context . Project . GetType ( ) , projectFileInfo , fileGenerator ) ;
1977+
1978+ manifestInputs . Add ( projectFileInfo . FullName ) ;
19661979 }
1967- else
1968- context . Options [ "AdditionalManifestFiles" ] = FileGeneratorUtilities . RemoveLineTag ;
1980+
1981+ if ( context . Configuration . AdditionalManifestFiles . Count > 0 )
1982+ manifestInputs . AddRange ( context . Configuration . AdditionalManifestFiles ) ;
19691983
19701984 if ( manifestInputs . Count > 0 )
19711985 {
19721986 Options . Vc . Linker . EmbedManifest embedManifest = Options . GetObject < Options . Vc . Linker . EmbedManifest > ( context . Configuration ) ;
19731987 if ( embedManifest == Options . Vc . Linker . EmbedManifest . No )
19741988 throw new NotImplementedException ( "Sharpmake does not support manifestinputs without embedding the manifest!" ) ;
19751989
1976- var cmdManifests = manifestInputs . Select ( p => Bff . CmdLineConvertIncludePathsFunc ( context , optionsContext . Resolver , p , "/manifestinput:" ) ) ;
1990+ if ( context . Configuration . IsFastBuild )
1991+ {
1992+ var cmdManifests = manifestInputs . Select ( p => Bff . CmdLineConvertIncludePathsFunc ( context , optionsContext . Resolver , p , "/manifestinput:" ) ) ;
19771993
1978- context . CommandLineOptions [ "ManifestInputs" ] = string . Join ( $ "'{ Environment . NewLine } + ' ", cmdManifests ) ;
1994+ // With fastbuild, manifest references are added to the .bff file via command line
1995+ context . Options [ "AdditionalManifestFiles" ] = FileGeneratorUtilities . RemoveLineTag ;
1996+ context . CommandLineOptions [ "ManifestInputs" ] = string . Join ( $ "'{ Environment . NewLine } + ' ", cmdManifests ) ;
1997+ }
1998+ else
1999+ {
2000+ // With msbuild, manifest references are added to the .vcxproj file via the AdditionalManifestFiles field
2001+ // See VcxProj.cs -> Template.Project.ProjectConfigurationsManifestTool use
2002+ context . Options [ "AdditionalManifestFiles" ] = string . Join ( ";" , Util . PathGetRelative ( context . ProjectDirectory , manifestInputs ) ) ;
2003+ context . CommandLineOptions [ "ManifestInputs" ] = FileGeneratorUtilities . RemoveLineTag ;
2004+ }
19792005 }
19802006 else
19812007 {
2008+ context . Options [ "AdditionalManifestFiles" ] = FileGeneratorUtilities . RemoveLineTag ;
19822009 context . CommandLineOptions [ "ManifestInputs" ] = FileGeneratorUtilities . RemoveLineTag ;
19832010 }
19842011 }
0 commit comments