Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable/Enable the default Target. #63

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<None Include="build\ILRepack.Lib.MSBuild.Task.nuspec"/>
<None Include="ILRepack.Config.props"/>
<None Include="ILRepack.Lib.MSBuild.Task.snk"/>
<None Include="ILRepack.Lib.MSBuild.Task.props" CopyToOutputDirectory="PreserveNewest"/>
<None Include="ILRepack.Lib.MSBuild.Task.targets" CopyToOutputDirectory="PreserveNewest"/>
</ItemGroup>

Expand Down
3 changes: 3 additions & 0 deletions ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<Project>
<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)ILRepack.Lib.MSBuild.Task.dll" TaskName="ILRepack"/>
</Project>
9 changes: 6 additions & 3 deletions ILRepack.Lib.MSBuild.Task/ILRepack.Lib.MSBuild.Task.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

<PropertyGroup>
<ILRepackTargetsFile Condition="$(ILRepackTargetsFile) == ''">$(ProjectDir)ILRepack.targets</ILRepackTargetsFile>
<ILRepackEnabled Condition="'$(ILRepackEnabled)' == '' and $(Configuration.Contains('Release'))">true</ILRepackEnabled>
<ILRepackEnabled Condition="'$(ILRepackEnabled)' == ''">false</ILRepackEnabled>
<ILRepackEnabled Condition="Exists('$(ILRepackTargetsFile)')">false</ILRepackEnabled>
<ClearOutputDirectory Condition="'$(ClearOutputDirectory)' == ''">true</ClearOutputDirectory>
</PropertyGroup>

<UsingTask AssemblyFile="$(MSBuildThisFileDirectory)ILRepack.Lib.MSBuild.Task.dll" TaskName="ILRepack"/>
<Import Project="$(ILRepackTargetsFile)" Condition="Exists('$(ILRepackTargetsFile)')"/>
<Target Name="ILRepack" AfterTargets="Build" Condition="$(Configuration.Contains('Release')) and !Exists('$(ILRepackTargetsFile)')">
<Target Name="ILRepack" AfterTargets="Build" Condition="$(ILRepackEnabled)">
<ItemGroup>
<InputAssemblies Include="$(OutputPath)$(TargetName)$(TargetExt)"/>
<InputAssemblies Include="$(OutputPath)*.dll" Exclude="$(OutputPath)$(TargetName)$(TargetExt)"/>
Expand All @@ -26,7 +29,7 @@
<Target
AfterTargets="ILRepack"
Name="CleanReferenceCopyLocalPaths"
Condition="$(Configuration.Contains('Release')) and !Exists('$(ILRepackTargetsFile)') and '$(ClearOutputDirectory)' != 'False'">
Condition="$(ILRepackEnabled) and $(ClearOutputDirectory)">
<Delete Files="@(ReferenceCopyLocalPaths->'$(OutDir)%(DestinationSubDirectory)%(Filename)%(Extension)')"/>
<ItemGroup>
<Directories Include="$([System.IO.Directory]::GetDirectories('$(OutDir)%(DestinationSubDirectory)', '*', System.IO.SearchOption.AllDirectories))"/>
Expand Down
29 changes: 22 additions & 7 deletions ILRepack.Lib.MSBuild.Task/ILRepack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -51,6 +52,14 @@ public virtual string LogFile
set => _logFile = BuildPath(ConvertEmptyToNull(value));
}

/// <summary>
/// Specifies the log task messages importance (High by default).
/// </summary>
public virtual string LogImportance {
get => _messageImportance.ToString();
set => Enum.TryParse(value, true, out _messageImportance);
}

/// <summary>
/// Merges types with identical names into one.
/// </summary>
Expand Down Expand Up @@ -300,7 +309,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
Expand All @@ -318,7 +327,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]);
}
Expand Down Expand Up @@ -348,7 +357,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
Expand All @@ -365,7 +374,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;
Expand All @@ -379,9 +388,15 @@ public override bool Execute()
}
}

#endregion

#region Private methods
/// <summary>
/// Logs a message with the specified format and arguments.
/// </summary>
/// <param name="message">The message format.</param>
/// <param name="messageArgs">The arguments for the message format.</param>
private void LogMessage(string message, params object[] messageArgs)
{
Log.LogMessage(_messageImportance, message, messageArgs);
}

/// <summary>
/// Parses the command line options for AllowedDuplicateNameSpaces.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
</metadata>
<files>
<file src="ILRepack.Lib.MSBuild.Task.dll" target="build"/>
<file src="ILRepack.Lib.MSBuild.Task.props" target="build"/>
<file src="ILRepack.Lib.MSBuild.Task.targets" target="build"/>
</files>
</package>
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ option only applies if you are using default targets file provided in NuGet pack
<KeyFile>$(ProjectDir)ILRepack.snk</KeyFile>
```

### 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
<ILRepackEnabled>false</ILRepackEnabled>
```

### 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
<ClearOutputDirectory>False</ClearOutputDirectory>
<ClearOutputDirectory>false</ClearOutputDirectory>
```

## Task options
Expand All @@ -109,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. |
| 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. |
Expand Down