Skip to content

Commit

Permalink
Add unmanaged assembly skipping to ILStrip task (dotnet#106267)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkurdek authored Aug 12, 2024
1 parent c71fd55 commit 78f5e87
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -237,5 +237,19 @@ public static void StripAssembly(string assemblyFile, string outputPath)
AssemblyDefinition assembly = AssemblyFactory.GetAssembly(assemblyFile);
AssemblyStripper.StripAssembly(assembly, outputPath);
}

public static bool TryStripAssembly(string assemblyFile, string outputPath)
{
try
{
StripAssembly(assemblyFile, outputPath);
return true;
}
// Skip unmanged assemblies
catch (ImageFormatException)
{
return false;
}
}
}
}
14 changes: 9 additions & 5 deletions src/tasks/MonoTargetsTasks/ILStrip/ILStrip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,7 @@ public override bool Execute()
}
});

if (TrimIndividualMethods)
{
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();
}
UpdatedAssemblies = ConvertAssembliesDictToOrderedList(_processedAssemblies, Assemblies).ToArray();

if (!result.IsCompleted && !Log.HasLoggedErrors)
{
Expand Down Expand Up @@ -130,7 +127,14 @@ private bool StripAssembly(ITaskItem assemblyItem)

try
{
AssemblyStripper.AssemblyStripper.StripAssembly (assemblyFile, outputPath);
if(!AssemblyStripper.AssemblyStripper.TryStripAssembly(assemblyFile, outputPath))
{
Log.LogMessage(MessageImportance.Low, $"[ILStrip] Skipping {assemblyFile} because it is not a managed assembly.");
}
else
{
_processedAssemblies.GetOrAdd(assemblyItem.ItemSpec, GetTrimmedAssemblyItem(assemblyItem, outputPath, assemblyFile));
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit 78f5e87

Please sign in to comment.