diff --git a/Directory.Build.props b/Directory.Build.props index d15d60ed..6c6db4e0 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -13,8 +13,6 @@ true true Level4 - - 4251 diff --git a/publish.py b/publish.py index ac4ea41c..9ee209fb 100644 --- a/publish.py +++ b/publish.py @@ -120,14 +120,10 @@ def remove_file(file): pass -for pattern in ["*.pdb", "*.lib", "*.exp", "*.winmd", "*.xml", "*.xbf"]: +for pattern in ["*.pdb", "*.lib", "*.exp"]: for file in glob.glob(pattern): remove_file(file) -for file in glob.glob("*.pri"): - if file != "resources.pri": - remove_file(file) - print("清理完毕", flush=True) ##################################################################### diff --git a/src/Common.Post.props b/src/Common.Post.props index 113e0a9c..56d4f677 100644 --- a/src/Common.Post.props +++ b/src/Common.Post.props @@ -1,16 +1,5 @@ - - en-US - true - true - true - low - $(SolutionDir)obj\$(Platform)\$(Configuration)\$(MSBuildProjectName)\ - $(IntDir)Generated Files\ - $(Configuration.EndsWith('Packaged')) - - @@ -62,4 +51,17 @@ + + + + + + + + + + + + + diff --git a/src/Common.Pre.props b/src/Common.Pre.props index 8c2317c8..0a67ed57 100644 --- a/src/Common.Pre.props +++ b/src/Common.Pre.props @@ -18,4 +18,10 @@ ARM64 + + + $(Configuration.StartsWith('Debug')) + $(Configuration.EndsWith('Packaged')) + en-US + diff --git a/src/Magpie.Core/Magpie.Core.vcxproj b/src/Magpie.Core/Magpie.Core.vcxproj index 5473d3d1..23a4f1cd 100644 --- a/src/Magpie.Core/Magpie.Core.vcxproj +++ b/src/Magpie.Core/Magpie.Core.vcxproj @@ -2,12 +2,19 @@ + true + true + true + true + low 16.0 Win32Proj {0e5205ae-dfa9-4cb8-b662-e43cd6512e2a} Magpie.Core 10.0.22621.0 Magpie.Core + $(SolutionDir)obj\$(Platform)\$(Configuration)\$(MSBuildProjectName)\ + $(IntDir)Generated Files\ $(SolutionDir)bin\$(Platform)\$(Configuration)\ diff --git a/src/Magpie/Magpie.vcxproj b/src/Magpie/Magpie.vcxproj index 3c41dff5..cd3cfe3b 100644 --- a/src/Magpie/Magpie.vcxproj +++ b/src/Magpie/Magpie.vcxproj @@ -2,31 +2,40 @@ + + true + true + true true + low true {1239537c-e5b8-427a-9e7f-ea443d1f3529} Magpie - Magpie + $(ProjectName) 17.0 false Windows Store 10.0 - 10.0.22621.0 + 10.0.22621.0 10.0.18362.0 $(SolutionDir)obj\$(Platform)\$(Configuration)\$(MSBuildProjectName)\ $(SolutionDir)bin\$(Platform)\$(Configuration)\ + $(IntDir)Generated Files\ x64|arm64 + true false nested - true + + true + + resources.pri - Application v143 @@ -642,6 +651,13 @@ + + + + + + + @@ -655,78 +671,13 @@ - - - - - - - - - - - - "); - priConfig.WriteLine(""); - - foreach (string priPath in PriPaths.Split(';')) { - priConfig.WriteLine($" "); - priConfig.WriteLine(""" - - - - - - - - - - - - - - - - """); - } - - priConfig.WriteLine(""); -} -// 调用 makepri 生成 resources.pri -Process p = Process.Start(new ProcessStartInfo { - FileName = makepriPath, - Arguments = "New /pr . /cf priconfig.xml /of resources.pri /o", - WorkingDirectory = OutDir, - UseShellExecute = false -}); -p.WaitForExit(); -if (p.ExitCode != 0) { - throw new Exception("生成 resources.pri 失败"); -} -File.Delete("priconfig.xml"); - ]]> - - - + + - <_PrisToMerge Include="@(PackagingOutputs)" Condition="'%(Extension)' == '.pri'" KeepMetadata="DoesntExist" /> - - - - - + <_PriFile Include="@(PackagingOutputs)" Condition="'%(Extension)' == '.pri' And '%(Filename)' != 'resources'" /> - + <_ManifestsDir>$(IntDir)Manifests\ @@ -734,8 +685,8 @@ File.Delete("priconfig.xml"); - - <_UnpackagedWin32WinmdManifest Include="@(ReferencePath->'$(_ManifestsDir)%(FileName).manifest')" Condition="'%(ReferencePath.IsSystemReference)' != 'true' And '%(ReferencePath.WinMDFile)' == 'true' And '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference' And '%(ReferencePath.Implementation)' != '' And '%(FileName)' != 'Microsoft.Web.WebView2.Core'"> + + <_UnpackagedWin32WinmdManifest Include="@(ReferencePath->'$(_ManifestsDir)%(FileName).manifest')" Condition="'%(ReferencePath.IsSystemReference)' != 'true' And '%(ReferencePath.WinMDFile)' == 'true' And '%(ReferencePath.ReferenceSourceTarget)' == 'ResolveAssemblyReference' And '%(ReferencePath.Implementation)' != ''"> %(ReferencePath.FullPath) $([System.IO.Path]::GetFileName('%(ReferencePath.Implementation)')) @@ -747,7 +698,7 @@ File.Delete("priconfig.xml"); - + @@ -773,4 +724,8 @@ File.Delete("priconfig.xml"); + + + $(CppWinRTMergedDir)$(RootNamespace).winmd + \ No newline at end of file diff --git a/src/WinUI.targets b/src/WinUI.targets index b5b31afe..485ccd78 100644 --- a/src/WinUI.targets +++ b/src/WinUI.targets @@ -1,21 +1,5 @@ - - - - <_TemporaryReferences Include="@(Reference)" Condition="'%(Extension)' == '.winmd' And '%(Reference.Private)' == ''" /> - - - false - - - <_WebView2Reference Include="@(Reference)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'" /> - - - - - - @@ -23,39 +7,40 @@ - + + + + dir) + .FirstOrDefault(dir => dir.Contains("10.")); +if (windowsSdkDir == null) { + throw new Exception("未找到 Windows SDK"); +} + +string makepriPath = Path.Combine(windowsSdkDir, "x64\\makepri.exe"); +if (!File.Exists(makepriPath)) { + throw new Exception("未找到 makepri"); +} + +void RunProcess(string fileName, string arguments, string errorMsg) { + Process process = Process.Start(new ProcessStartInfo { + FileName = makepriPath, + Arguments = arguments, + WorkingDirectory = intDir, + UseShellExecute = false + }); + process.WaitForExit(); + + if (process.ExitCode != 0) { + throw new Exception(errorMsg); + } +} + +// 将 pri 转储为 xml +RunProcess(makepriPath, "dump /if Microsoft.UI.Xaml.pri /dt detailed /o", "转储 pri 失败"); + +// 加载并解析 resources.pri.xml +string dumpFileName = "resources.pri.xml"; +XDocument xmlDocument = XDocument.Load(dumpFileName); + +// 删除冗余资源 +foreach (var resourceNode in xmlDocument.Descendants("NamedResource")) { + string name = resourceNode.Attribute("name")?.Value; + if (name == null || !name.EndsWith(".xbf")) { + continue; + } + + // 我们仅需 19h1 和 21h1 的资源,分别用于 Win10 和 Win11。 + // 小写 compact 仅存在于预发行版 WinUI 的资源中。 + foreach (var key in new[] { "compact", "Compact", "v1", "rs2", "rs3", "rs4", "rs5" }) { + if (name.Contains(key)) { + var base64Value = resourceNode.Descendants("Base64Value").FirstOrDefault(); + if (base64Value != null) { + // 将文件内容替换为一个空格(Base64 为 "IA==") + base64Value.Value = "IA=="; + } + break; + } + } +} + +xmlDocument.Save(dumpFileName); + +// 创建 priconfig.xml +string configFileName = "priconfig.xml"; +string priconfigContent = @" + + + + + + + + + + + + + + + + + + + + +"; +File.WriteAllText(configFileName, priconfigContent, Encoding.UTF8); + +// 将 xml 重新封装成 pri +RunProcess(makepriPath, "new /pr . /of Microsoft.UI.Xaml.pri /cf " + configFileName + " /in Microsoft.UI.Xaml /o", "封装 pri 失败"); + +// 删除临时文件 +File.Delete(dumpFileName); +File.Delete(configFileName); ]]> - - + + + + + <_WinUIWinmdReference Include="@(ReferencePath)" Condition="'%(Filename)%(Extension)' == 'Microsoft.UI.Xaml.winmd'" /> + + + <_WebView2Reference Include="@(ReferencePath)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'" /> + + + + <_ReferenceRelatedPaths Remove="@(_ReferenceRelatedPaths)" Condition="'%(Filename)' == 'Microsoft.Web.WebView2.Core'" /> + + + + <_ReferenceRelatedPaths Remove="@(_ReferenceRelatedPaths)" Condition="'%(Filename)' == 'Microsoft.UI.Xaml' And '%(Extension)' != '.winmd'" /> - - - + + + - + + + $(IsPackaged) $(WinUIDllPath) + + + + + - - - <_ReferenceRelatedPaths Remove="@(WinUIPriReference)" /> - + <_ReferenceRelatedPaths Include="$(WinUIPriPath)"> - %(WinUIPriReference.CopyLocal) - %(WinUIPriReference.CopyLocalSatelliteAssemblies) - %(WinUIPriReference.Implicit) - %(WinUIPriReference.OriginalItemSpec) - %(WinUIPriReference.Private) - %(WinUIPriReference.ReferenceOutputAssembly) - %(WinUIPriReference.ResolvedFrom) - %(WinUIPriReference.Version) + false + true + false - + + + + + + - + + + <_AllChildProjectItemsWithTargetPath Remove="@(_AllChildProjectItemsWithTargetPath)" Condition="$([System.String]::new('%(TargetPath)').StartsWith('Microsoft.UI.Xaml\'))" /> + + + + - <_AllChildProjectItemsWithTargetPath Remove="@(_AllChildProjectItemsWithTargetPath)" Condition="$([System.String]::new('%(TargetPath)').StartsWith('Microsoft.UI.Xaml'))" /> + <_ExpandedPriPayload Remove="@(_ExpandedPriPayload)" Condition="$([System.String]::new('%(TargetPath)').StartsWith('Microsoft.UI.Xaml\'))" />