.exe in \bin\Release is obfuscated but .exe in c:\Program Files after installation is not
pel
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
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.
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?
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?