From dab7930aead58f15d479c5c735739d45994fede3 Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Tue, 21 Jun 2022 13:14:36 +0100 Subject: [PATCH] windows: generate app manifests for all exe projects Automatically generate the correct application manifest for Windows executable projects that we produce. The manifests are required on Windows systems newer than Windows 8 to correctly access versioning APIs that will otherwise always report "Windows 8", even on later versions. The manifest we generate states we are compatible with all versions of Windows from 7 to 11 (inclusive). --- Directory.Build.props | 6 ++++ Directory.Build.targets | 27 +++++++++++++++ build/GCM.MSBuild.csproj | 13 ++++++++ build/GCM.tasks | 16 +++++++++ build/GenerateWindowsAppManifest.cs | 51 +++++++++++++++++++++++++++++ 5 files changed, 113 insertions(+) create mode 100644 Directory.Build.targets create mode 100644 build/GCM.MSBuild.csproj create mode 100644 build/GCM.tasks create mode 100644 build/GenerateWindowsAppManifest.cs diff --git a/Directory.Build.props b/Directory.Build.props index 7f78555c7..3abe378a3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -18,6 +18,12 @@ $(RepoPath)src\ $(RepoPath)out\ $(RepoPath)assets\ + + + <_IsExeProject Condition="'$(OutputType)' == 'Exe' OR '$(OutputType)' == 'WinExe'">true + + + true diff --git a/Directory.Build.targets b/Directory.Build.targets new file mode 100644 index 000000000..3c84f230d --- /dev/null +++ b/Directory.Build.targets @@ -0,0 +1,27 @@ + + + + + + + + + + $(IntermediateOutputPath)app.manifest + + + + + + + + + + + diff --git a/build/GCM.MSBuild.csproj b/build/GCM.MSBuild.csproj new file mode 100644 index 000000000..7dbe90afe --- /dev/null +++ b/build/GCM.MSBuild.csproj @@ -0,0 +1,13 @@ + + + + netstandard2.0 + false + + + + + + + + diff --git a/build/GCM.tasks b/build/GCM.tasks new file mode 100644 index 000000000..fe7031f34 --- /dev/null +++ b/build/GCM.tasks @@ -0,0 +1,16 @@ + + + <_TaskAssembly>$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll + <_TaskFactory>CodeTaskFactory + + + <_TaskAssembly>$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll + <_TaskFactory>RoslynCodeTaskFactory + + + + + + + + diff --git a/build/GenerateWindowsAppManifest.cs b/build/GenerateWindowsAppManifest.cs new file mode 100644 index 000000000..58a94c5a1 --- /dev/null +++ b/build/GenerateWindowsAppManifest.cs @@ -0,0 +1,51 @@ +using Microsoft.Build.Framework; +using Microsoft.Build.Utilities; +using System.IO; + +namespace GitCredentialManager.MSBuild +{ + public class GenerateWindowsAppManifest : Task + { + [Required] + public string Version { get; set; } + + [Required] + public string ApplicationName { get; set; } + + [Required] + public string OutputFile { get; set; } + + public override bool Execute() + { + Log.LogMessage(MessageImportance.Normal, "Creating application manifest file for '{0}'...", ApplicationName); + + string manifestDirectory = Path.GetDirectoryName(OutputFile); + if (!Directory.Exists(manifestDirectory)) + { + Directory.CreateDirectory(manifestDirectory); + } + + File.WriteAllText( + OutputFile, + $@" + + + + + + + + + + + + + + + +"); + + return true; + } + } +}