MSBuild Obfuscation

dotnetpro
dotnetpro used Ask the Experts™
on
Experts,

I am using C# 2008 to write my WPF application and i publish using ClickOnce. I am using following updates to the .csproj file to obfuscate the .exe after compilation
 <Target Name="BeforeRebuild" Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <CreateProperty Value="true">
      <Output TaskParameter="Value" PropertyName="Obfuscate" />
    </CreateProperty>
  </Target>
  <Target Name="AfterCompile" Condition=" '$(Obfuscate)' != '' ">
    <Exec Command="&quot;C:\Program Files\Microsoft Visual Studio 9.0\Application\PreEmptive Solutions\Dotfuscator Community Edition\dotfuscator.exe&quot; -q Dotfuscator.xml" />
    <Copy SourceFiles="$(ProjectDir)Dotfuscated\$(TargetFileName)" DestinationFiles="$(IntermediateOutputPath)$(TargetFileName)" />
  </Target>

But in the published version when i use ILDASM to look at the .exe its not obfuscated..I think its the Copy task that is not woking...Any ideas as to either how can else can i obfuscate my .exe or any way to check whether Copy is working or not ????
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
Hi, from my experience you need a professional program to obfuscate your code. In this case DotFuscator and such...

Author

Commented:
I am trying to make a strong case for that. But i had written a sample "Hello World" app and i tried to obfuscate...which actually did and now the same app is not obfuscated anymore....I am pretty sure it did at that time and not anymore is killing me...

Commented:
Ok, now I understand, you are integrating DotFuscator into ClickOnce. I searched in google and it looks OK Maybe the Exec Command is wrong.
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

Author

Commented:
Ok..when i right click on the project and rebuild ...it opens the Dotfuscator CE edition and prompts me Obfuscate...i obfuscate and close the Dotfuscator window that's when the rebuild completes. But its supposed to sign, create manifests and publish the dotfuscated assembly where as it does that with the non-obfuscated one..

Author

Commented:
Do you know if there is any way to check/verify whether Copy task is executing right ?
Commented:
no, sorry.
If you check your Bin\Release\Dotfuscate\
(or where the compiled obfuscated files should be), do you see that it is obfuscated?

Maybe the problem is that it copies to the setup the wrong files (the non-obfuscated files).

If the files in the Dotfuscate directory are not obfuscated then maybe something is wrong with DotFuscator
(Which in that case you should try compiling your Exe first and then obfuscating it directory from the DotFuscator and see if it goes well without any error. Maybe the setting of the program on what to Obfuscate has changed)

Author

Commented:
In the Dotfuscated folder created by the Dotfuscator.exe the target .exe is obfuscated. If i rebuild instead of Publish then i see in bin/Release, the .exe is obfuscated...Only when i publish it , its not obfuscated...I am still scratching my head..
Is the rebuilt exe added to the publisher reference or is it looking for the debug version or somewhere else for the new obfuscated exe?

Author

Commented:
I think that's what the Copy task in the XML is supposed to do.But not sure if that is happening because published exe is not obfuscated
It doesn't sound like it is doin what you want.
On your copy path your not adding a "\", so try replacing it with this.

    <Copy SourceFiles="$(ProjectDir)Dotfuscated\$(TargetFileName)" DestinationFiles="$(IntermediateOutputPath)\$(TargetFileName)" />

Author

Commented:
Driving now . Will try in a few minutes :))

Author

Commented:
Still the same.. Here is the sequence of events...
1 Built a sample App called ApptoDeploy
2 Updated the .CSPROJ file with XML  and saved.
3 Compiled project and changed to "Release" mode.
4 Created Dotfuscated.xml file by pointing the dotfuscator CE to the ApptoDeply.exe under obj/Release folder.
5 Then rebuilt the project which opened up the dotfuscator.exe application. I ran the dotfuscator which created Dotfuscated folder with ApptoDeploy.exe and Map.xml as contents of it.
5 Then published it to http://localhost/ApptoDeploy.
6 Checked the published version's Application Files and ApptoDeploy.exe.deploy as shown in ILDASM is still unobfuscated..


 Checked the ApptoDeploy.exe.deploy under ILDASM and it still shows

Author

Commented:
Turns out even the professional edition is not very ClickOnce efficient. But i appreciate every answer.

Author

Commented:
Answers were helpful but i had to resort to using Smart Assembly Obfuscator.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial