From f744408fe939f88725b0eba9f82573d4d57e4dce Mon Sep 17 00:00:00 2001 From: Martin Ashton Date: Wed, 21 May 2025 23:27:40 -0400 Subject: [PATCH 1/5] Implemented Vim.Format.ILMerge and its product Vim.Format.Standalone.dll --- .../util/Vim.Util.Tests/Vim.Util.Tests.csproj | 3 -- src/cs/util/Vim.Util/Reflection.cs | 16 +++----- src/cs/vim-format.sln | 14 +++++++ .../Vim.Format.ILMerge.Tests.csproj | 29 ++++++++++++++ .../VimFormatILMergeTests.cs | 23 +++++++++++ .../Vim.Format.ILMerge.csproj | 40 +++++++++++++++++++ 6 files changed, 112 insertions(+), 13 deletions(-) create mode 100644 src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj create mode 100644 src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs create mode 100644 src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj diff --git a/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj b/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj index 0e938e53..649eead3 100644 --- a/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj +++ b/src/cs/util/Vim.Util.Tests/Vim.Util.Tests.csproj @@ -12,9 +12,6 @@ all runtime; build; native; contentfiles; analyzers; buildtransitive - - - diff --git a/src/cs/util/Vim.Util/Reflection.cs b/src/cs/util/Vim.Util/Reflection.cs index 77caaf8f..72cb63da 100644 --- a/src/cs/util/Vim.Util/Reflection.cs +++ b/src/cs/util/Vim.Util/Reflection.cs @@ -18,18 +18,11 @@ public static IEnumerable GetAllSubclassesOf(this Assembly asm, Type t) public static IEnumerable GetAllFields(this Type self) => self.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); - /// - /// Ignores the property or the field when they are being enumerated from a given object. - /// - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class IgnoreInReflectedListAttribute : Attribute { } - /// /// Converts fields to a dictionary of string/object pair. /// public static IDictionary FieldsToDictionary(this object self) => self.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance) - .Where(fi => !fi.GetCustomAttributes().Any()) .ToDictionary(fi => fi.Name, fi => fi.GetValue(self)); /// @@ -37,13 +30,16 @@ public static IDictionary FieldsToDictionary(this object self) /// public static IDictionary PropertiesToDictionary(this object self) => self.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance) - .Where(pi => !pi.GetCustomAttributes().Any()) .ToDictionary(pi => pi.Name, fi => fi.GetValue(self)); /// /// Converts properties to an enumerable of strings. /// - public static IEnumerable PropertiesToStrings(this object self) - => self.PropertiesToDictionary().Select(kv => $"{kv.Key}: {kv.Value}"); + public static IEnumerable PropertiesToStrings(this object self, Func keyFilter = null) + { + return self.PropertiesToDictionary() + .Where(kv => keyFilter?.Invoke(kv.Key) ?? true) + .Select(kv => $"{kv.Key}: {kv.Value}"); + } } } diff --git a/src/cs/vim-format.sln b/src/cs/vim-format.sln index 6a7a027f..fb20d3c7 100644 --- a/src/cs/vim-format.sln +++ b/src/cs/vim-format.sln @@ -59,6 +59,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Gltf.Converter", "sampl EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Vim.Gltf.Converter.Tests", "samples\Vim.Gltf.Converter.Tests\Vim.Gltf.Converter.Tests.csproj", "{902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vim.Format.ILMerge", "vim\Vim.Format.ILMerge\Vim.Format.ILMerge.csproj", "{3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Vim.Format.ILMerge.Tests", "vim\Vim.Format.ILMerge.Tests\Vim.Format.ILMerge.Tests.csproj", "{26C02A1E-168B-2945-8AD2-7E7C30114F91}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -149,6 +153,14 @@ Global {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Debug|Any CPU.Build.0 = Debug|Any CPU {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Release|Any CPU.ActiveCfg = Release|Any CPU {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3}.Release|Any CPU.Build.0 = Release|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF}.Release|Any CPU.Build.0 = Release|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Debug|Any CPU.Build.0 = Debug|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Release|Any CPU.ActiveCfg = Release|Any CPU + {26C02A1E-168B-2945-8AD2-7E7C30114F91}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -175,6 +187,8 @@ Global {A0FA4646-67AC-4310-9BA5-53D2D7CF218F} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} {8C81050A-951C-418F-BBA8-76EE0353863C} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} {902CF0A5-3433-4CF4-AEFB-E1E0E7A5A3F3} = {E2EBD5E0-81EC-4720-833C-05ECE1BA84A1} + {3EA06057-7FF8-C92D-16EE-28A0AFE3AEEF} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} + {26C02A1E-168B-2945-8AD2-7E7C30114F91} = {D639C635-01D1-48C4-89B5-1FD70F1AFEE9} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {7D1BF641-26E8-4809-B638-029241C51BE2} diff --git a/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj b/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj new file mode 100644 index 00000000..ed44c980 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge.Tests/Vim.Format.ILMerge.Tests.csproj @@ -0,0 +1,29 @@ + + + + net8.0 + + + + + + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + false + + + true + ..\Vim.Format.ILMerge\bin\$(Configuration)\Vim.Format.Standalone.dll + + + + diff --git a/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs new file mode 100644 index 00000000..b8d66831 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs @@ -0,0 +1,23 @@ +using NUnit.Framework; +using System.IO; +using Vim.Util.Logging; + +namespace Vim.Format.ILMerge.Tests; + +[TestFixture] +public static class VimFormatILMergeTests +{ + [Test] + public static void TestVimFormatStandalone() + { + // This test makes use of the merged version of serilog. + // We had to create a merged standalone version of Vim.Format to minimize collisions with other assemblies in Revit. + var fileName = "standalone.log"; + + var logger = Util.Logging.Serilog.Log.Init("toot", fileName, true); + logger.LogInformation("this is a log message for the baked-in version of serilog"); + + var fileInfo = new FileInfo(fileName); + Assert.IsTrue(fileInfo.Exists, $"File not found: {fileInfo.FullName}"); + } +} diff --git a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj new file mode 100644 index 00000000..4094d4d8 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj @@ -0,0 +1,40 @@ + + + + netstandard2.0 + false + Always + Vim.Format.ILMerge + + true + + + + + + + + + + + + + + From 7feb98198f48356af9dcc022e626626e697229b0 Mon Sep 17 00:00:00 2001 From: Martin Ashton Date: Thu, 22 May 2025 06:58:44 -0400 Subject: [PATCH 2/5] Updated test --- .../VimFormatILMergeTests.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs index b8d66831..d4693ad0 100644 --- a/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs +++ b/src/cs/vim/Vim.Format.ILMerge.Tests/VimFormatILMergeTests.cs @@ -1,6 +1,8 @@ using NUnit.Framework; using System.IO; +using Vim.Util; using Vim.Util.Logging; +using Serilog; namespace Vim.Format.ILMerge.Tests; @@ -13,11 +15,27 @@ public static void TestVimFormatStandalone() // This test makes use of the merged version of serilog. // We had to create a merged standalone version of Vim.Format to minimize collisions with other assemblies in Revit. var fileName = "standalone.log"; + var msg = "This is a log message which uses the ILMerged version of serilog"; - var logger = Util.Logging.Serilog.Log.Init("toot", fileName, true); - logger.LogInformation("this is a log message for the baked-in version of serilog"); + { + // setup + IO.Delete(fileName); + Assert.IsTrue(!File.Exists(fileName)); + } - var fileInfo = new FileInfo(fileName); - Assert.IsTrue(fileInfo.Exists, $"File not found: {fileInfo.FullName}"); + { + // action + var logger = Util.Logging.Serilog.Log.Init("toot", fileName, true); + logger.LogInformation(msg); + Log.CloseAndFlush(); + } + + { + // verify + var fileInfo = new FileInfo(fileName); + Assert.IsTrue(fileInfo.Exists, $"File not found: {fileInfo.FullName}"); + var logged = File.ReadAllText(fileInfo.FullName); + Assert.IsTrue(logged.Contains(msg)); + } } } From 484ea2477bb601b5da426e5ee8401902aaac2ada Mon Sep 17 00:00:00 2001 From: Martin Ashton Date: Thu, 22 May 2025 09:29:44 -0400 Subject: [PATCH 3/5] Retargeting to ILRepack --- .../vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj index 4094d4d8..4ac12619 100644 --- a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj +++ b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj @@ -15,13 +15,16 @@ - - - + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + - Date: Fri, 23 May 2025 11:33:26 -0400 Subject: [PATCH 4/5] Hoping for cross-platform ilrepack build target --- .../Vim.Format.ILMerge/ILRepack.Config.props | 8 +++ .../vim/Vim.Format.ILMerge/ILRepack.targets | 45 +++++++++++++ .../Vim.Format.ILMerge.csproj | 64 ++++++++----------- 3 files changed, 79 insertions(+), 38 deletions(-) create mode 100644 src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props create mode 100644 src/cs/vim/Vim.Format.ILMerge/ILRepack.targets diff --git a/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props b/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props new file mode 100644 index 00000000..780712a3 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/ILRepack.Config.props @@ -0,0 +1,8 @@ + + + + + False + $(ProjectDir)ILRepack.targets + + \ No newline at end of file diff --git a/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets new file mode 100644 index 00000000..cd1eafa4 --- /dev/null +++ b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj index 4ac12619..c3413f18 100644 --- a/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj +++ b/src/cs/vim/Vim.Format.ILMerge/Vim.Format.ILMerge.csproj @@ -1,43 +1,31 @@  - - netstandard2.0 - false - Always - Vim.Format.ILMerge - - true - + + netstandard2.0 + false + Always + Vim.Format.ILMerge + + true + - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - + + + + + all + runtime; build; native; contentfiles; analyzers; buildtransitive + + + + + + + + + - - - From 57135fc95c4c90da8c6ffca4adfd7515251ed712 Mon Sep 17 00:00:00 2001 From: Martin Ashton Date: Fri, 23 May 2025 11:48:59 -0400 Subject: [PATCH 5/5] Removed explicit v4 target --- src/cs/vim/Vim.Format.ILMerge/ILRepack.targets | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets index cd1eafa4..f0482766 100644 --- a/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets +++ b/src/cs/vim/Vim.Format.ILMerge/ILRepack.targets @@ -18,7 +18,6 @@