From e04ae22ddc8dc9db0657b6f81a957b20caeaf189 Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Fri, 22 Nov 2019 10:01:42 -0500 Subject: [PATCH 1/5] Try avoiding emitting assembly to run setup process --- .../Mono.Addins.SetupProcess.csproj | 47 ++++++++++ .../Properties/AssemblyInfo.cs | 20 +++++ Mono.Addins.SetupProcess/SetupProcessTool.cs | 75 ++++++++++++++++ Mono.Addins.sln | 12 +++ Mono.Addins/AssemblyInfo.cs | 4 + .../Mono.Addins.Database/SetupProcess.cs | 89 +------------------ 6 files changed, 161 insertions(+), 86 deletions(-) create mode 100644 Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj create mode 100644 Mono.Addins.SetupProcess/Properties/AssemblyInfo.cs create mode 100644 Mono.Addins.SetupProcess/SetupProcessTool.cs diff --git a/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj b/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj new file mode 100644 index 00000000..ac559781 --- /dev/null +++ b/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj @@ -0,0 +1,47 @@ + + + + Debug + AnyCPU + 8.0.30703 + 2.0 + {303D2716-94AA-4067-8111-F478D26DFAFE} + Exe + Mono.Addins.SetupProcess + Mono.Addins.SetupProcess + True + ..\mono-addins.snk + v4.7.2 + + + true + full + false + ..\bin + DEBUG; + prompt + 4 + true + + + true + ..\bin + prompt + 4 + true + + + + + + + + + + + {91DD5A2D-9FE3-4C3C-9253-876141874DAD} + Mono.Addins + + + + \ No newline at end of file diff --git a/Mono.Addins.SetupProcess/Properties/AssemblyInfo.cs b/Mono.Addins.SetupProcess/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..6edd5dd1 --- /dev/null +++ b/Mono.Addins.SetupProcess/Properties/AssemblyInfo.cs @@ -0,0 +1,20 @@ +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following +// attributes. +// +// change them to the information which is associated with the assembly +// you compile. + +[assembly: AssemblyTitle("Mono.Addins.SetupProcess")] +[assembly: AssemblyCopyright("Copyright (C) 2007 Novell, Inc (http://www.novell.com)")] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all values by your own or you can build default build and revision +// numbers with the '*' character (the default): + +[assembly: AssemblyVersion("1.0.0.0")] diff --git a/Mono.Addins.SetupProcess/SetupProcessTool.cs b/Mono.Addins.SetupProcess/SetupProcessTool.cs new file mode 100644 index 00000000..6c68546c --- /dev/null +++ b/Mono.Addins.SetupProcess/SetupProcessTool.cs @@ -0,0 +1,75 @@ +// +// SetupProcessTool.cs +// +// Author: +// Marius Ungureanu +// +// Copyright (c) 2019 Microsoft Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using Mono.Addins.Database; + +namespace Mono.Addins.SetupProcess +{ + class SetupProcessTool + { + public static int Main (string [] args) + { + ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args [0])); + + try { + string registryPath = Console.In.ReadLine (); + string startupDir = Console.In.ReadLine (); + string addinsDir = Console.In.ReadLine (); + string databaseDir = Console.In.ReadLine (); + + AddinDatabase.RunningSetupProcess = true; + AddinRegistry reg = new AddinRegistry (registryPath, startupDir, addinsDir, databaseDir); + + switch (args [1]) { + case "scan": { + string folder = args.Length > 2 ? args [2] : null; + if (folder.Length == 0) folder = null; + + var context = new ScanOptions (); + context.Read (Console.In); + reg.ScanFolders (monitor, folder, context); + break; + } + case "pre-scan": { + string folder = args.Length > 2 ? args [2] : null; + if (folder.Length == 0) folder = null; + var recursive = bool.Parse (Console.In.ReadLine ()); + reg.GenerateScanDataFilesInProcess (monitor, folder, recursive); + break; + } + case "get-desc": + var outFile = Console.In.ReadLine (); + reg.ParseAddin (monitor, args [2], args [3]); + break; + } + } catch (Exception ex) { + monitor.ReportError ("Unexpected error in setup process", ex); + return 1; + } + return 0; + } + } +} diff --git a/Mono.Addins.sln b/Mono.Addins.sln index e33045ba..54bb8d3c 100644 --- a/Mono.Addins.sln +++ b/Mono.Addins.sln @@ -41,6 +41,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Addins.MSBuild", "Mono EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Addins.GuiGtk3", "Mono.Addins.GuiGtk3\Mono.Addins.GuiGtk3.csproj", "{410A7DC9-E7DA-43E6-B592-93E2A344B660}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Mono.Addins.SetupProcess", "Mono.Addins.SetupProcess\Mono.Addins.SetupProcess.csproj", "{303D2716-94AA-4067-8111-F478D26DFAFE}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution DebugWin32|Any CPU = DebugWin32|Any CPU @@ -209,6 +211,16 @@ Global {FEC19BDA-4904-4005-8C09-68E82E8BEF6A}.DebugWin32|Any CPU.Build.0 = Debug|Any CPU {FEC19BDA-4904-4005-8C09-68E82E8BEF6A}.Release|Any CPU.ActiveCfg = Release|Any CPU {FEC19BDA-4904-4005-8C09-68E82E8BEF6A}.Release|Any CPU.Build.0 = Release|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugWin32|Any CPU.ActiveCfg = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugWin32|Any CPU.Build.0 = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.Release|Any CPU.Build.0 = Release|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugNoGui|Any CPU.ActiveCfg = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugNoGui|Any CPU.Build.0 = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugGtk3|Any CPU.ActiveCfg = Debug|Any CPU + {303D2716-94AA-4067-8111-F478D26DFAFE}.DebugGtk3|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(NestedProjects) = preSolution {F109148D-849E-4044-8700-5E8EA0AB2476} = {7EFC0684-310E-417D-B8BD-5584C3F34BD5} diff --git a/Mono.Addins/AssemblyInfo.cs b/Mono.Addins/AssemblyInfo.cs index 7b050f17..8b5a9d05 100644 --- a/Mono.Addins/AssemblyInfo.cs +++ b/Mono.Addins/AssemblyInfo.cs @@ -23,6 +23,10 @@ "0400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c" + "3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4" + "f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] +[assembly: InternalsVisibleTo ("Mono.Addins.SetupProcess, PublicKey=00240000048000009400000006020000002400005253413100" + + "0400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c" + + "3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4" + + "f9fccf84d15069089380284dbdd35f46cdff12a1bd78e4ef0065d016df")] [assembly: InternalsVisibleTo("UnitTests, PublicKey=00240000048000009400000006020000002400005253413100" + "0400000100010079159977d2d03a8e6bea7a2e74e8d1afcc93e8851974952bb480a12c9134474d04062447c37e0e68c080536fcf3c" + "3fbe2ff9c979ce998475e506e8ce82dd5b0f350dc10e93bf2eeecf874b24770c5081dbea7447fddafa277b22de47d6ffea449674a4" + diff --git a/Mono.Addins/Mono.Addins.Database/SetupProcess.cs b/Mono.Addins/Mono.Addins.Database/SetupProcess.cs index 0ae3a337..d23fde9b 100644 --- a/Mono.Addins/Mono.Addins.Database/SetupProcess.cs +++ b/Mono.Addins/Mono.Addins.Database/SetupProcess.cs @@ -68,10 +68,10 @@ internal static void ExecuteCommand (IProgressStatus monitor, string registryPat sb.Append (" \"").Append (arg1).Append ("\""); Process process = new Process (); - - string asm = null; + + string thisAsm = typeof (SetupProcess).Assembly.Location; + string asm = Path.GetDirectoryName (thisAsm) + "Mono.Addins.SetupProcess.dll"; try { - asm = CreateHostExe (); if (!Util.IsMono) process.StartInfo = new ProcessStartInfo (asm, sb.ToString ()); else { @@ -107,90 +107,7 @@ internal static void ExecuteCommand (IProgressStatus monitor, string registryPat } catch (Exception ex) { Console.WriteLine (ex); throw; - } finally { - if (asm != null) { - try { - File.Delete (asm); - } catch { } - } - } - } - - public static int Main (string [] args) - { - ProcessProgressStatus monitor = new ProcessProgressStatus (int.Parse (args [0])); - - try { - string registryPath = Console.In.ReadLine (); - string startupDir = Console.In.ReadLine (); - string addinsDir = Console.In.ReadLine (); - string databaseDir = Console.In.ReadLine (); - - AddinDatabase.RunningSetupProcess = true; - AddinRegistry reg = new AddinRegistry (registryPath, startupDir, addinsDir, databaseDir); - - switch (args [1]) { - case "scan": { - string folder = args.Length > 2 ? args [2] : null; - if (folder.Length == 0) folder = null; - - var context = new ScanOptions (); - context.Read (Console.In); - reg.ScanFolders (monitor, folder, context); - break; - } - case "pre-scan": { - string folder = args.Length > 2 ? args [2] : null; - if (folder.Length == 0) folder = null; - var recursive = bool.Parse (Console.In.ReadLine ()); - reg.GenerateScanDataFilesInProcess (monitor, folder, recursive); - break; - } - case "get-desc": - var outFile = Console.In.ReadLine (); - reg.ParseAddin (monitor, args [2], args [3]); - break; - } - } catch (Exception ex) { - monitor.ReportError ("Unexpected error in setup process", ex); - return 1; } - return 0; - } - - static string CreateHostExe () - { - string file; - string id; - string fullFile; - do { - id = Guid.NewGuid ().ToString ().Replace ('-','_'); - file = id + ".exe"; - fullFile = Path.Combine (Path.GetTempPath (), file); - } while (File.Exists (fullFile)); - - AssemblyName aname = new AssemblyName (); - aname.Name = id; - AssemblyBuilder ab = AppDomain.CurrentDomain.DefineDynamicAssembly (aname, AssemblyBuilderAccess.Save, Path.GetTempPath ()); - ModuleBuilder mb = ab.DefineDynamicModule (aname.Name, file); - TypeBuilder tb = mb.DefineType ("App", TypeAttributes.Public|TypeAttributes.Class); - - MethodBuilder fb = tb.DefineMethod("Main", - MethodAttributes.Public | - MethodAttributes.Static, - typeof(int), new Type[] { typeof(string[]) }); - - MethodInfo mi = typeof(SetupProcess).GetMethod ("Main", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static); - - ILGenerator ilg = fb.GetILGenerator(); - ilg.Emit (OpCodes.Ldarg_0); - ilg.EmitCall (OpCodes.Call, mi, null); - ilg.Emit (OpCodes.Ret); - - tb.CreateType(); - ab.SetEntryPoint (fb, PEFileKinds.WindowApplication); - ab.Save (file); - return fullFile; } } From b03d3fa8a7f7e36a87f0107dd6fc3159c5991bfb Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 8 Feb 2021 17:13:35 +0000 Subject: [PATCH 2/5] Fix incorrect setup process path The path was being created without the path separator for the Mono.Addins.SetupProcess assembly. Also the file extension was incorrectly set to .dll when running with Mono. --- Mono.Addins/Mono.Addins.Database/SetupProcess.cs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Mono.Addins/Mono.Addins.Database/SetupProcess.cs b/Mono.Addins/Mono.Addins.Database/SetupProcess.cs index d23fde9b..e3da3266 100644 --- a/Mono.Addins/Mono.Addins.Database/SetupProcess.cs +++ b/Mono.Addins/Mono.Addins.Database/SetupProcess.cs @@ -69,8 +69,13 @@ internal static void ExecuteCommand (IProgressStatus monitor, string registryPat Process process = new Process (); - string thisAsm = typeof (SetupProcess).Assembly.Location; - string asm = Path.GetDirectoryName (thisAsm) + "Mono.Addins.SetupProcess.dll"; + string thisAsmDir = Path.GetDirectoryName (typeof (SetupProcess).Assembly.Location); + string asm; + if (Util.IsMono) + asm = Path.Combine (thisAsmDir, "Mono.Addins.SetupProcess.exe"); + else + asm = Path.Combine (thisAsmDir, "Mono.Addins.SetupProcess.dll"); + try { if (!Util.IsMono) process.StartInfo = new ProcessStartInfo (asm, sb.ToString ()); From 9680723c3339febd50aed39bab43cc4080a7bf28 Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 8 Feb 2021 17:14:51 +0000 Subject: [PATCH 3/5] Fix SetupProcess project's target framework The project was hard coded to target .NET 4.7.2 instead of using the TargetFramework.props file. This was preventing it being referenced by the UnitTests project. --- Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj b/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj index ac559781..8200891e 100644 --- a/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj +++ b/Mono.Addins.SetupProcess/Mono.Addins.SetupProcess.csproj @@ -1,5 +1,6 @@ + Debug AnyCPU @@ -11,7 +12,6 @@ Mono.Addins.SetupProcess True ..\mono-addins.snk - v4.7.2 true From 8ea73ddb3c484963c2f830bb5dd18a11d14cc18f Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 8 Feb 2021 17:15:47 +0000 Subject: [PATCH 4/5] UnitTests now local copy the SetupProcess exe The tests do not run tests with the external SetupProcess currently but having the UnitTests copy this allows this to be tested locally by changing the AddinDatabase.GetSetupHandler method. --- Test/UnitTests/UnitTests.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Test/UnitTests/UnitTests.csproj b/Test/UnitTests/UnitTests.csproj index c0329a32..68cb5947 100644 --- a/Test/UnitTests/UnitTests.csproj +++ b/Test/UnitTests/UnitTests.csproj @@ -45,6 +45,10 @@ {A85C9721-C054-4BD8-A1F3-0227615F0A36} Mono.Addins.Setup + + {303D2716-94AA-4067-8111-F478D26DFAFE} + Mono.Addins.SetupProcess + From 28be40a37113d37acd6a3c09efe561866e67744a Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Mon, 8 Feb 2021 17:49:28 +0000 Subject: [PATCH 5/5] Fix IndexOutOfRangeException when using get-desc with SetupProcess Fixed the setup process tool trying to use too many command line arguments. The out directory is passed on stdin not as a command line argument. --- Mono.Addins.SetupProcess/SetupProcessTool.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Mono.Addins.SetupProcess/SetupProcessTool.cs b/Mono.Addins.SetupProcess/SetupProcessTool.cs index 6c68546c..65f00324 100644 --- a/Mono.Addins.SetupProcess/SetupProcessTool.cs +++ b/Mono.Addins.SetupProcess/SetupProcessTool.cs @@ -62,7 +62,7 @@ public static int Main (string [] args) } case "get-desc": var outFile = Console.In.ReadLine (); - reg.ParseAddin (monitor, args [2], args [3]); + reg.ParseAddin (monitor, args [2], outFile); break; } } catch (Exception ex) {