Obfuscate multiple assemblies (you know, like a normal project)
I have gone through the forum; I see that there has been
many requests for this feature however nothing within the last few years. I am
hoping that there has been something added as we have just upgraded to the
latest version.
I have a large project with many assemblies (120) and want to keep them all separate. I am currently running the command for each file using a single template project file (.saproj)
This is taking about an hour, prone to error and is killing our testing pipeline.
Ideally would like to provide a list file or multiple items into the /input command.
I feel that there could be many parts of this process that could be cached and speed the process up. like license check, call and dependency tree, project settings, etc
Redgate, is this feature on your backlog at all?
Answers
As you say, it's been often requested and also considered multiple times. While it remains a possibility, it's not an imminent feature.
We create a Microsoft.Build.Traversal ( https://github.com/microsoft/MSBuildSdks/blob/main/src/Traversal/README.md ) project named something like Obfuscatable.dirs.proj, which has ProjectReferences to all the projects that need obfuscation.
The traversal project contains a target modeled on the Microsoft.Build.Traversal SDK's standard targets for building/testing entire groups of projects:
<Target Name="OurObfuscationTraversalTarget">
<MSBuild Projects="@(ProjectReference)"
Targets="OurObfuscationTarget"
BuildInParallel="true"
Properties="%(ProjectReference.SetConfiguration); %(ProjectReference.SetPlatform); %(ProjectReference.SetTargetFramework)"
SkipNonexistentProjects="$(SkipNonexistentProjects)"
SkipNonexistentTargets="$(SkipNonexistentTargets)"
StopOnFirstFailure="$(StopOnFirstFailure)"
ContinueOnError="$([MSBuild]::ValueOrDefault('$(TestContinueOnError)', '$(ContinueOnError)'))" />
</Target>
Then for the individual projects, we define a "OurObfuscationTarget" target, which uses the task <SmartAssembly ProjectFile="$(AssemblyName).saproj" />, and is configured to know when an obfuscation target is up-to-date an can be skipped by MSBuild.
Parallel obfuscation is then performed by calling: dotnet msbuild -t:OurObfuscationTraversalTarget Obfuscatable.dirs.proj
This is generally much faster than obfuscating each project one-by-one.