Skip to content

Instantly share code, notes, and snippets.

@dmunch
Created April 13, 2014 20:57
Show Gist options
  • Save dmunch/10602023 to your computer and use it in GitHub Desktop.
Save dmunch/10602023 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="AfterResolveReferences">
<CallTarget Targets="Obfuscate"/>
</Target>
<Target Name="AfterClean">
<CallTarget Targets="CleanObfuscate"/>
</Target>
<Target Name="GetTargets">
<MSBuild Projects="@(ProjectReference)" Targets="GetTargetPath">
<Output TaskParameter="TargetOutputs" ItemName="Targets" />
</MSBuild>
</Target>
<Target Name="Obfuscate"
DependsOnTargets="GetTargets"
Inputs="%(Targets.fullpath)"
Outputs="$(IntermediateOutputPath)\Obfuscation\%(Targets.filename)%(Targets.extension)">
<PropertyGroup>
<DefineConstants>ObfsDir=$(IntermediateOutputPath)\Obfuscation\</DefineConstants>
</PropertyGroup>
<CreateItem Include="@(Targets->'%(relativedir)\*.dll')">
<Output TaskParameter="Include" ItemName="Dependencies"/>
</CreateItem>
<MakeDir Directories="$(IntermediateOutputPath)\Obfuscation\"/>
<!-- Copy all references to intermediate output path -->
<Copy SourceFiles='%(Targets.fullpath)' DestinationFolder='$(IntermediateOutputPath)\Obfuscation\'/>
<!-- Copy all dependencies -->
<Copy SourceFiles='@(Dependencies)' DestinationFolder='$(IntermediateOutputPath)\Obfuscation\'/>
<!-- Start obfuscator -->
<Exec Command='Obfuscator.exe "$(IntermediateOutputPath)\Obfuscation\%(Targets.filename)%(Targets.extension)"'/>
</Target>
<Target Name='CleanObfuscate'>
<CreateItem Include='$(IntermediateOutputPath)\Obfuscation\*.*'>
<Output TaskParameter="Include" ItemName="FilesToRemove"/>
</CreateItem>
<Delete Files='@(FilesToRemove)'/>
<RemoveDir Directories='$(IntermediateOutputPath)\Obfuscation\'></RemoveDir>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment