From efea8c5db18819a1f38183c86b241bbf4af76979 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sun, 25 Aug 2024 22:29:30 -0300 Subject: [PATCH 1/7] Move `UsingTask` to `.props`. --- ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj | 1 + ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props | 3 +++ ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets | 1 - .../build/ILRepack.Lib.MSBuild.Task.nuspec | 1 + 4 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj index 58d6b8a..1802bff 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj @@ -18,6 +18,7 @@ + diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props new file mode 100644 index 0000000..d8e77e3 --- /dev/null +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets index 1c6fc63..0e530ac 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets @@ -5,7 +5,6 @@ $(ProjectDir)ILRepack.targets - diff --git a/ILRepack.Lib.MSBuild.Task/build/ILRepack.Lib.MSBuild.Task.nuspec b/ILRepack.Lib.MSBuild.Task/build/ILRepack.Lib.MSBuild.Task.nuspec index 83d4682..ef851ba 100644 --- a/ILRepack.Lib.MSBuild.Task/build/ILRepack.Lib.MSBuild.Task.nuspec +++ b/ILRepack.Lib.MSBuild.Task/build/ILRepack.Lib.MSBuild.Task.nuspec @@ -19,6 +19,7 @@ + From 01b0c211f2fb37c0f89b319e0a4ef2a82b5fcf8f Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sun, 25 Aug 2024 22:38:43 -0300 Subject: [PATCH 2/7] Add `ILRepackEnabled` property to disable default Target --- .../ILRepack.Lib.MSBuild.Task.targets | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets index 0e530ac..bbe9132 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets @@ -3,10 +3,14 @@ $(ProjectDir)ILRepack.targets + true + false + false + true - + @@ -25,7 +29,7 @@ + Condition="$(ILRepackEnabled) and $(ClearOutputDirectory)"> From 7b065f66793be7ba0fc1737db018fea87393b8dd Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sun, 25 Aug 2024 22:54:25 -0300 Subject: [PATCH 3/7] Update readme with default Target and `ILRepackEnabled` --- README.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 043f895..1ab9e62 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,22 @@ option only applies if you are using default targets file provided in NuGet pack $(ProjectDir)ILRepack.snk ``` +### Disable default ILRepack Target + +By default if no "ILRepack.targets" file is found a default ILRepack Target runs after build if the configuration contains "Release". +You can disable this behavior by setting the following property to `false` or `true` to enable it. + +```xml +false +``` + ### Specify whether to clear directory after merging If you are using default targets file then you may notice that it clears Output directory after merging dependencies. You can turn this functionality off by setting ClearOutputDirectory to False as shown below. ```xml -False +false ``` ## Task options From f09e297fc1a1477777a72382d686d75c2ab410cc Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sun, 25 Aug 2024 23:09:48 -0300 Subject: [PATCH 4/7] Add `LogTaskMessage` feature --- ILRepack.Lib.MSBuild.Task/ILRepack.cs | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.cs b/ILRepack.Lib.MSBuild.Task/ILRepack.cs index 8dc4ba6..6ec3075 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.cs +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.cs @@ -51,6 +51,11 @@ public virtual string LogFile set => _logFile = BuildPath(ConvertEmptyToNull(value)); } + /// + /// Specifies whether to log task messages. + /// + public virtual bool LogTaskMessage { get; set; } = true; + /// /// Merges types with identical names into one. /// @@ -300,7 +305,7 @@ public override bool Execute() throw new Exception($"Unable to resolve assembly '{assemblies[i]}'"); } - Log.LogMessage(MessageImportance.High, "Added assembly '{0}'", assemblies[i]); + LogMessage("Added assembly '{0}'", assemblies[i]); } // List of regex to compare against FullName of types NOT to internalize @@ -318,7 +323,7 @@ public override bool Execute() $"Invalid internalize exclude pattern at item index {i}. Pattern cannot be blank."); } - Log.LogMessage(MessageImportance.High, + LogMessage( "Excluding namespaces/types matching pattern '{0}' from being internalized", internalizeExclude[i]); } @@ -348,7 +353,7 @@ public override bool Execute() repackOptions.SearchDirectories = searchPath.ToArray(); // Attempt to merge assemblies. - Log.LogMessage(MessageImportance.High, "Merging {0} assembl{1} to '{2}'", + LogMessage("Merging {0} assembl{1} to '{2}'", InputAssemblies.Length, InputAssemblies.Length != 1 ? "ies" : "y", _outputFile); // Measure performance @@ -365,7 +370,7 @@ public override bool Execute() stopWatch.Stop(); - Log.LogMessage(MessageImportance.High, "Merge succeeded in {0} s", stopWatch.Elapsed.TotalSeconds); + LogMessage("Merge succeeded in {0} s", stopWatch.Elapsed.TotalSeconds); logger.Close(); return true; @@ -379,9 +384,16 @@ public override bool Execute() } } - #endregion - - #region Private methods + /// + /// Logs a message with the specified format and arguments. + /// + /// The message format. + /// The arguments for the message format. + private void LogMessage(string message, params object[] messageArgs) + { + var importance = LogTaskMessage ? MessageImportance.High : MessageImportance.Low; + Log.LogMessage(importance, message, messageArgs); + } /// /// Parses the command line options for AllowedDuplicateNameSpaces. From 23bbcd1b499935c78e8c1e1001345aaf5c7b34b6 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Sun, 25 Aug 2024 23:17:36 -0300 Subject: [PATCH 5/7] Update `LogTaskMessageImportance` in readme --- ILRepack.Lib.MSBuild.Task/ILRepack.cs | 6 +++--- README.md | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.cs b/ILRepack.Lib.MSBuild.Task/ILRepack.cs index 6ec3075..e4cd70c 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.cs +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.cs @@ -52,9 +52,9 @@ public virtual string LogFile } /// - /// Specifies whether to log task messages. + /// Specifies the log task messages importance (High/true by default). /// - public virtual bool LogTaskMessage { get; set; } = true; + public virtual bool LogTaskMessageImportance { get; set; } = true; /// /// Merges types with identical names into one. @@ -391,7 +391,7 @@ public override bool Execute() /// The arguments for the message format. private void LogMessage(string message, params object[] messageArgs) { - var importance = LogTaskMessage ? MessageImportance.High : MessageImportance.Low; + var importance = LogTaskMessageImportance ? MessageImportance.High : MessageImportance.Low; Log.LogMessage(importance, message, messageArgs); } diff --git a/README.md b/README.md index 1ab9e62..ea5b54b 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,7 @@ You can turn this functionality off by setting ClearOutputDirectory to False as | KeyFile | Specifies a key file to sign the output assembly. | | LibraryPath | List of paths to use as "include directories" when attempting to merge assemblies. | | LogFile | Specifies a log file to output log information. | +| LogTaskMessageImportance | Specifies the log message importance in the task. (`true` by default) | | MergeIlLinkerFiles | Merge IL Linker file XML resources from Microsoft assemblies (optional). Same-named XML resources ('ILLink.*.xml') will be combined during merging. | | NoRepackRes | Does not add the embedded resource 'ILRepack.List' with all merged assembly names. | | OutputFile | Output name for the merged assembly. | From fee1bd11e380d9ffd4b83856c1989dea890a72c6 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Mon, 26 Aug 2024 00:04:14 -0300 Subject: [PATCH 6/7] Update `LogImportance` to use enum --- ILRepack.Lib.MSBuild.Task/ILRepack.cs | 13 +++++++++---- README.md | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.cs b/ILRepack.Lib.MSBuild.Task/ILRepack.cs index e4cd70c..5fd2322 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.cs +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.cs @@ -19,6 +19,7 @@ public class ILRepack : Microsoft.Build.Utilities.Task, IDisposable private string _keyContainer; private ILRepacking.ILRepack.Kind _targetKind; private string _excludeFileTmpPath; + private MessageImportance _messageImportance = MessageImportance.High; #endregion @@ -52,9 +53,12 @@ public virtual string LogFile } /// - /// Specifies the log task messages importance (High/true by default). + /// Specifies the log task messages importance (High by default). /// - public virtual bool LogTaskMessageImportance { get; set; } = true; + public virtual string LogImportance { + get => _messageImportance.ToString(); + set => Enum.TryParse(value, true, out _messageImportance); + } /// /// Merges types with identical names into one. @@ -391,10 +395,11 @@ public override bool Execute() /// The arguments for the message format. private void LogMessage(string message, params object[] messageArgs) { - var importance = LogTaskMessageImportance ? MessageImportance.High : MessageImportance.Low; - Log.LogMessage(importance, message, messageArgs); + Log.LogMessage(_messageImportance, message, messageArgs); } + + /// /// Parses the command line options for AllowedDuplicateNameSpaces. /// diff --git a/README.md b/README.md index ea5b54b..b780ff3 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ You can turn this functionality off by setting ClearOutputDirectory to False as | KeyFile | Specifies a key file to sign the output assembly. | | LibraryPath | List of paths to use as "include directories" when attempting to merge assemblies. | | LogFile | Specifies a log file to output log information. | -| LogTaskMessageImportance | Specifies the log message importance in the task. (`true` by default) | +| LogImportance | Specifies the log message importance in the task. (`high` by default, `normal` and `low` available) | | MergeIlLinkerFiles | Merge IL Linker file XML resources from Microsoft assemblies (optional). Same-named XML resources ('ILLink.*.xml') will be combined during merging. | | NoRepackRes | Does not add the embedded resource 'ILRepack.List' with all merged assembly names. | | OutputFile | Output name for the merged assembly. | From 5ccf69f09dddbb968ba141b5ed48c874d6dbbab9 Mon Sep 17 00:00:00 2001 From: Luiz Henrique Cassettari Date: Mon, 26 Aug 2024 00:14:27 -0300 Subject: [PATCH 7/7] Clear spaces --- ILRepack.Lib.MSBuild.Task/ILRepack.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/ILRepack.Lib.MSBuild.Task/ILRepack.cs b/ILRepack.Lib.MSBuild.Task/ILRepack.cs index 5fd2322..32c430a 100644 --- a/ILRepack.Lib.MSBuild.Task/ILRepack.cs +++ b/ILRepack.Lib.MSBuild.Task/ILRepack.cs @@ -398,8 +398,6 @@ private void LogMessage(string message, params object[] messageArgs) Log.LogMessage(_messageImportance, message, messageArgs); } - - /// /// Parses the command line options for AllowedDuplicateNameSpaces. ///