.exe in \bin\Release is obfuscated but .exe in c:\Program Files after installation is not

pelpel Posts: 4 New member
I just learned that the .exe in the \bin\Release folder is obfuscated, but after checking the .exe in \Program Files after installation using the setup & deployment package, it is not obfuscated.   Is there a switch setting I need to over-ride in the "product-final-target" setting of the setup solution so that it grabs the .exe in the bin\Release folder?
Tagged:

Answers

  • pelpel Posts: 4 New member
    Dear Support, I got the setup program (.msi) to install the obfuscated .exe in c:\Program Files without using the Nuget install, and rather by using a manual setup as follows.   You should go through this to make sure that when first saving the destination .exe into \bin\Release, the obfuscation does not pick up the previously obfuscated .exe in \obj\Release.   I did speak with tech support a whiloe ago today, and it was not clear which executable should imported into the SA GUI at first, before saving it in the "destination" as \obj\Release -- since you cannot import and save an assembly in the SA GUI in the same directory.  You'll have to figure that out.  Overwriting is overwriting, but if you use the .exe in \obj\Release during a compile, then you will be opening an already obfuscated .exe from a previous build -- so you need to straighten out where to initially import an assembly from, and where to set the destination (obj\Release).

    Below are the steps necessary to get a successful installation of an obfuscated Winforms app (VB.NET) that users install via a Setup & Deployment package (i.e., .msi file):

     

    1.  In Project Settings-->Compile, set the output target to obj\Release

     

    2.  Without using the SA GUI (that you download and install), make sure you have already compiled your Winform project without obfuscation, so that there are executable files (.exe) in both the obj\Release and \bin\Release folders

     

    3.  Next, open the SA GUI (software package installed in Windows), and import the “assembly” i.e., .exe file for your project that’s in the \bin\Release folder.  

     

    4. Set the “destination” for the output target (obfuscated .exe) to the \obj\Release folder

     

    4.  Using the SA GUI, go through the obfuscation settings and when done at the bottom page of settings, click on Save As, and save the SA project file (.saproj) in the same folder that contains the VS Project Solution file (.sln) and the .vbproj (or .csproj) files, using a name that’s the same as your project. 

     

    5.  In the folder where you saved the SA project file (.saproj), open the project file with extension .vbproj (or .csproj).  Navigate to the very end (bottom) of the file and add the following code:

     

    <!-- SmartAssembly task -->

     <PropertyGroup>

          <SmartAssemblyProjectFile>$(ProjectDir)$(AssemblyName).saproj</SmartAssemblyProjectFile>

        <_SATaskAssembly>SmartAssembly.MSBuild.Tasks, Version=7.0.0.0, Culture=neutral, PublicKeyToken=7f465a1c156d4d57</_SATaskAssembly>

      </PropertyGroup>

      <UsingTask TaskName="SmartAssembly.MSBuild.Tasks.Build" AssemblyName="$(_SATaskAssembly)" />

      <Target Name="BuildWithSmartAssembly" AfterTargets="Build" Condition=" '$(Configuration)' == 'Release' ">

        <SmartAssembly.MSBuild.Tasks.Build ProjectFile="$(SmartAssemblyProjectFile)" />

      </Target>

      <!-- /SmartAssembly task -->

      <Target Name="BeforeBuild" Condition=" '$(Configuration)' == 'Release' ">

        <CreateProperty Value="true">

          <Output TaskParameter="Value" PropertyName="RunSmartAssembly" />

        </CreateProperty>

      </Target>

      <Target Name="AfterCompile" Condition=" '$(RunSmartAssembly)' != '' ">

        <Copy SourceFiles=".\obj\Release\$(TargetFileName)" DestinationFiles=".\obj\Release\$(TargetName).temp$(TargetExt)" />

        <SmartAssembly.MSBuild.Tasks.Build ProjectFile="C:\MyVBProjectsFolder\ThisVBProject\ProjectName.saproj" Input="$(ProjectDir)obj\Release\$(TargetName).exe" OverwriteAssembly="True" />

      </Target>

     

    The yellow-highlighted code lists the full directory location where the SA project file (.saproj) is located, which includes the filename.  

     

    6.   Everything should be ready for you to now compile the Project, and bundle into the Setup & Deployment Project.

     

    7.   Run the setup file (.msi) and ensure that the installed executable in Windows c:\Program Files [or c:\Program Files(x86)] is obfuscated by opening it with ILDASM, .NET Reflector, or some other program that can open assemblies (.exe files). 

     

    8.  You can now successfully distribute the installation setup program (.msi) with the obfuscated assembly.


  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    Hi @pel!

    Just copying the answer from https://forum.red-gate.com/discussion/86594/setup-of-sa-for-net-winforms-app-vb-net#latest here:

    When using MSI or ClickOnce, msbuild will use the assembly it finds in the obj\Release folder as the assembly in the resulting installer.

    Thus you will indeed need to use the obj\release assembly as the input assembly, and instruct SmartAssembly to overwrite the original obj\Release file with the obfuscated one. You can do this by adding the following to your csproj/vsproj file:

    <SmartAssemblyOverwriteAssembly>true</SmartAssemblyOverwriteAssembly>

    (for more information, see here for using the nuget package and here for manually adding the SA build task)

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


  • pelpel Posts: 4 New member
    Thanks, but what's not clear yet, is when starting a new project in the SA GUI, what folder should be used as the "destination" of the assembly.  Since, as you know, if you import the assembly from \obj\Release, you cannot use obj\Release as the destination? 
  • Jessica RJessica R Posts: 1,319 Rose Gold 4
    edited March 5, 2020 2:49AM
    Hi @pel!

    The destination assembly you choose in the GUI/project can be anywhere, you just need to make sure the overwrite option is on in your vbproj\csproj file, so that the output goes to obj/Release. :)

    Jessica Ramos | Product Support Engineer | Redgate Software

    Have you visited our Help Center?


Sign In or Register to comment.