11

I would like to ask if it is possible to use Fody-Costura, which embeds dependencies into the executable and Obfuscar, for obfuscation, together.

At the moment I’m struggling because the msbuild target in Visual Studio 2017 of Costura gets executed before the one of obfuscar (which then complains about missing dependency files).

As obfuscar does not provide a target by itself, I'm using MSBuild.Obfuscar.

Is there a way to combine those two, maybe by specifying the order of the targets?

TheGuy
  • 161
  • 1
  • 11

2 Answers2

2

I made a quick Framework console app project, and I added Costura, MSBuild.Obfuscar, and NLog. In order to get Obfuscar to work, all I had to do was edit the Obfuscar.xml file to include the actual assembly name:

<?xml version="1.0" encoding="utf-8"?>
<Obfuscator>
  <Var name="InPath" value="bin\Release" />
  <Var name="OutPath" value="$(InPath)\obfuscated" />
  <Var name="HidePrivateApi" value="true" />
  <!-- was: file="$(InPath)\"  -->
  <Module file="$(InPath)\ConsoleApp1.exe" />
</Obfuscator>

This built for me just fine. The resulting assembly had my code obfuscated and also included NLog as a resource. If you're seeing different results, then maybe it has to do with the specific other NuGet packages your solution includes.

asherber
  • 2,508
  • 1
  • 15
  • 12
  • I am using the same configuration as you do. The problem occurs as soon as MahApps.Metro is added, without it everything works just fine. I'll now try to find a solution for that. Thanks – TheGuy Mar 06 '18 at 22:23
  • Since you mentioned MahApps.Metro, I tried again with a WPF project, with Costura, MSBuild.Obfuscar, NLog, and MahApps.Metro. It also built fine for me, no errors. – asherber Mar 07 '18 at 00:38
  • Have you just added the package or are you actively using it? Because when I just add the package it works like a charm, but as soon as I replace the normal window with the metro window it stops working. – TheGuy Mar 07 '18 at 21:00
  • I did replace the main window with a metro window, in the XAML and code behind, but I didn't add any controls or code. If there are specific steps I should take to reproduce, please let me know. – asherber Mar 07 '18 at 21:47
  • 1
    Fody costura compress dll files, and It is not ofuscated, if you save the file with ILSpy and decompress with https://github.com/G4224T/Fody-Costura-Decompress and see again the result with ILSpy it file is not obfuscate, Did you could resolve it? – Zaha Jul 10 '19 at 19:38
  • @JuanPablo You are exactly right. The compressed assemblies are not obfuscated. – TheLegendaryCopyCoder Feb 05 '22 at 12:14
0

I was able to reproduce the error. I used the answer from asherber, but as soon as I changed the build to release, it didn't work anymore.
("Unable to resolve dependency: MahApps.Metro")

In order to make it build successfully even on release, I had to copy the referenced MahApps.Metro.dll into the Release folder.
If you installed from NuGet, you can find the .dll in the packages folder in your project folder.

Skelvir
  • 64
  • 5