diff --git a/nuget/Microsoft.Windows.CsWinRT.targets b/nuget/Microsoft.Windows.CsWinRT.targets index 2ce814b4d..e9a29d767 100644 --- a/nuget/Microsoft.Windows.CsWinRT.targets +++ b/nuget/Microsoft.Windows.CsWinRT.targets @@ -149,8 +149,34 @@ $(CsWinRTFilters) - - + + + + $(CsWinRTGuidPatchPath) + $(CsWinRTGuidPatchRuntimePath) + + $(CsWinRTPath)build\tools\ + $(CsWinRTPath)lib\net5.0\ + + @(BuiltProjectOutputGroupKeyOutput->'%(Identity)') + + + + + + + + + + + + + + + diff --git a/src/Directory.Build.props b/src/Directory.Build.props index eee4c5c30..a0ee6a9e3 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -26,6 +26,11 @@ $(DefineConstants);MANUAL_IUNKNOWN + + $(MSBuildProjectDirectory)\Perf\GuidPatch\bin\$(Platform)\$(Configuration)\net5.0\ + $(MSBuildProjectDirectory)\WinRT.Runtime\bin\$(Configuration)\net5.0\ + + 0.0.0.0 0.0.0-private.0 diff --git a/src/Perf/GuidPatch/GuidPatch.csproj b/src/Perf/GuidPatch/GuidPatch.csproj index c9ca52748..3d9a8f99a 100644 --- a/src/Perf/GuidPatch/GuidPatch.csproj +++ b/src/Perf/GuidPatch/GuidPatch.csproj @@ -4,7 +4,7 @@ Exe net5.0 enable - AnyCPU;x64;x86 + AnyCPU diff --git a/src/Perf/GuidPatch/GuidPatcher.cs b/src/Perf/GuidPatch/GuidPatcher.cs index 2af033fb1..00e7e82cb 100644 --- a/src/Perf/GuidPatch/GuidPatcher.cs +++ b/src/Perf/GuidPatch/GuidPatcher.cs @@ -30,7 +30,7 @@ class GuidPatcher private readonly TypeDefinition guidDataBlockType; private SignatureGenerator signatureGenerator; - public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver) + public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver, AssemblyDefinition winRTRuntime) { assembly = AssemblyDefinition.ReadAssembly(assemblyPath, new ReaderParameters(ReadingMode.Deferred) { @@ -42,7 +42,7 @@ public GuidPatcher(string assemblyPath, IAssemblyResolver assemblyResolver) ApplyWindowsRuntimeProjections = false }); - winRTRuntimeAssembly = assemblyResolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default)); + winRTRuntimeAssembly = winRTRuntime; // assemblyResolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default)); guidImplementationDetailsType = new TypeDefinition(null, "", TypeAttributes.AutoClass | TypeAttributes.Sealed, assembly.MainModule.TypeSystem.Object); diff --git a/src/Perf/GuidPatch/Program.cs b/src/Perf/GuidPatch/Program.cs index 0f993eb01..579788732 100644 --- a/src/Perf/GuidPatch/Program.cs +++ b/src/Perf/GuidPatch/Program.cs @@ -1,4 +1,6 @@ -using System; +using Mono.Cecil; +using System; +using System.IO; namespace GuidPatch { @@ -6,21 +8,35 @@ class Program { static void Main(string[] args) { - Console.WriteLine("Hello World!"); + if (args.Length != 2) + { + Console.WriteLine($"Expected to be given two arguments. Given {args.Length}"); + } + else + { + /* The first argument given is the .dll to patch + The second argument is the folder to look for winrt.runtime in */ + var resolver = new DefaultAssemblyResolver(); - /* - var resolver = new DefaultAssemblyResolver(); - resolver.AddSearchDirectory("TestData"); - resolver.AddSearchDirectory("C:/Program Files/dotnet/packs/Microsoft.NETCore.App.Ref/5.0.0/ref/net5.0"); - var guidPatcher = new GuidPatcher( - "TestData/Windows.dll", - resolver); - int numPatches = guidPatcher.ProcessAssembly(); - Directory.CreateDirectory("Output"); - guidPatcher.SaveAssembly("Output"); - - Console.WriteLine($"{numPatches} IID calculations/fetches patched"); - */ + try + { + resolver.AddSearchDirectory(args[1]); + AssemblyDefinition winRTRuntimeAssembly = resolver.Resolve(new AssemblyNameReference("WinRT.Runtime", default)); + var guidPatcher = new GuidPatcher( + args[0], + resolver, + winRTRuntimeAssembly); + int numPatches = guidPatcher.ProcessAssembly(); + Directory.CreateDirectory("GuidPatcherOutput"); + guidPatcher.SaveAssembly("GuidPatcherOutput"); + Console.WriteLine($"{numPatches} IID calculations/fetches patched"); + } + catch (AssemblyResolutionException) + { + Console.WriteLine("Failed to resolve WinRT.Runtime, shutting down."); + return; + } + } } } } diff --git a/src/build.cmd b/src/build.cmd index d738a1a6b..2ca794b53 100644 --- a/src/build.cmd +++ b/src/build.cmd @@ -131,6 +131,7 @@ if ErrorLevel 1 ( exit /b !ErrorLevel! ) if "%cswinrt_build_only%"=="true" goto :eof +if "%cswinrt_buildpack%"=="true" goto :package :test :unittest @@ -184,7 +185,7 @@ set net5_runtime=%this_dir%WinRT.Runtime\bin\%cswinrt_configuration%\net5.0\WinR set source_generator=%this_dir%Authoring\WinRT.SourceGenerator\bin\%cswinrt_configuration%\netstandard2.0\WinRT.SourceGenerator.dll set winrt_host_%cswinrt_platform%=%this_dir%_build\%cswinrt_platform%\%cswinrt_configuration%\WinRT.Host\bin\WinRT.Host.dll set winrt_shim=%this_dir%Authoring\WinRT.Host.Shim\bin\%cswinrt_configuration%\net5.0\WinRT.Host.Shim.dll -set guid_patch=%this_dir%Perf\GuidPatch\bin\%cswinrt_configuration%\net5.0\GuidPatch.exe +set guid_patch=%this_dir%Perf\GuidPatch\bin\%cswinrt_platform%\%cswinrt_configuration%\net5.0\GuidPatch.exe echo Creating nuget package call :exec %nuget_dir%\nuget pack %this_dir%..\nuget\Microsoft.Windows.CsWinRT.nuspec -Properties cswinrt_exe=%cswinrt_exe%;netstandard2_runtime=%netstandard2_runtime%;net5_runtime=%net5_runtime%;source_generator=%source_generator%;cswinrt_nuget_version=%cswinrt_version_string%;winrt_host_x86=%winrt_host_x86%;winrt_host_x64=%winrt_host_x64%;winrt_host_arm=%winrt_host_arm%;winrt_host_arm64=%winrt_host_arm64%;winrt_shim=%winrt_shim%;guid_patch=%guid_patch% -OutputDirectory %cswinrt_bin_dir% -NonInteractive -Verbosity Detailed -NoPackageAnalysis goto :eof diff --git a/src/cswinrt.sln b/src/cswinrt.sln index b28214168..0f0219794 100644 --- a/src/cswinrt.sln +++ b/src/cswinrt.sln @@ -101,7 +101,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "AuthoringWinUITest", "Tests EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Perf", "Perf", "{539DBDEF-3B49-4503-9BD3-7EB83C2179CB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GuidPatch", "Perf\GuidPatch\GuidPatch.csproj", "{AE3B0611-2FBB-42AB-A245-B4E79868A5F9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "GuidPatch", "Perf\GuidPatch\GuidPatch.csproj", "{AE3B0611-2FBB-42AB-A245-B4E79868A5F9}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -299,7 +299,6 @@ Global {41E2A272-150F-42F5-AD40-047AAD9088A0}.Release|x86.Build.0 = Release|x86 {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|Any CPU.ActiveCfg = Debug|Win32 {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x64.ActiveCfg = Debug|x64 - {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x64.Build.0 = Debug|x64 {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x86.ActiveCfg = Debug|Win32 {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Debug|x86.Build.0 = Debug|Win32 {0212A7C5-8D3F-443C-9EBC-1F28091FDF88}.Release|Any CPU.ActiveCfg = Release|Win32 @@ -341,7 +340,6 @@ Global {FC05C557-C974-4CB3-9DA7-BB5476710E91}.Release|x86.Build.0 = Release|Any CPU {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|Any CPU.ActiveCfg = Debug|x86 {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.ActiveCfg = Debug|x64 - {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.Build.0 = Debug|x64 {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x64.Deploy.0 = Debug|x64 {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x86.ActiveCfg = Debug|x86 {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Debug|x86.Build.0 = Debug|x86 @@ -355,7 +353,6 @@ Global {75B1621F-EC51-4D77-BD7E-BEE576B3ADC9}.Release|x86.Deploy.0 = Release|x86 {493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|Any CPU.ActiveCfg = Debug|Win32 {493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x64.ActiveCfg = Debug|x64 - {493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x64.Build.0 = Debug|x64 {493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x86.ActiveCfg = Debug|Win32 {493C7729-2F21-4198-AB09-BDF56BF501D3}.Debug|x86.Build.0 = Debug|Win32 {493C7729-2F21-4198-AB09-BDF56BF501D3}.Release|Any CPU.ActiveCfg = Release|Win32 diff --git a/src/cswinrt/main.cpp b/src/cswinrt/main.cpp index 75b31dfd2..4a1fff5cb 100644 --- a/src/cswinrt/main.cpp +++ b/src/cswinrt/main.cpp @@ -119,6 +119,7 @@ Where is one or more of: int result{}; writer w; + /* Special case the usage exceptions to print CLI options */ try { auto start = get_start_time();