2

I am trying to obfuscate bunch of files in a directory and every build there are more and more files being generated. I would like to know if there is a way I can dynamically create the Dotfuscator configuration xml file using a MSBUILD task that will generate the xml file every time there is a new file added to the directory?

varun7447
  • 574
  • 1
  • 6
  • 27

2 Answers2

2

This might be a good time to use the Directory input. Rather than representing a single assembly (.exe or .dll), this type of Dotfuscator input captures all the assemblies in a directory. When the contents of the directory change, Dotfuscator's build will automatically pick up any new assemblies.

To make a Dotfuscator config file with a Directory input, open the GUI and add an input as you normally would (directions for Community Edition's GUI and for Professional Edition's standalone GUI), but instead of selecting a file from the Browse... dialog, just navigate to the directory and click "Open" while the "File name" is still listed as "Folder Select". Then, save your configuration.

From now on, whenever you run Dotfuscator (whether from the standalone GUI, the command line, the Visual Studio integration, or the MSBuild task), all assemblies in the directory will be processed as input.

Note: If you look at the config file itself, you might be surprised that it will still list individual assemblies:

<input>
  <loadpaths />
  <asmlist>
    <package refid="19e1b0c5-7221-476f-af4b-bafef68edc95">
      <file dir="C:\code\BasicTestApp\BasicTestApp\bin" name="Debug" />
      <asmlist>
        <inputassembly refid="a6da5d8d-c181-4103-840d-d8cc7c85937a">
          <option>honoroas</option>
          <option>stripoa</option>
          <option>transformxaml</option>
          <file dir="" name="BasicTestApp.exe" />
        </inputassembly>
        <inputassembly refid="df84dad0-fbe8-49ab-b8c8-9fb59e706785">
          <option>honoroas</option>
          <option>stripoa</option>
          <option>library</option>
          <option>transformxaml</option>
          <file dir="" name="ClassLibrary.dll" />
        </inputassembly>
      </asmlist>
    </package>
  </asmlist>
</input>

Despite this layout, Dotfuscator will process all assemblies in the C:\code\BasicTestApp\BasicTestApp\bin\Debug directory when it runs a build based off this config file, not just those two listed. The assembly elements in the config are just there so that you can still make rules against individual assemblies in the GUI (e.g., to make one assembly be in Library Mode). The list represents the state of the directory when the GUI last modified the config.

Disclaimer: I work for the Dotfuscator team, and am answering this question as part of my job.


Additional note due to clarification in the comments: the directory package has a feature where you can exclude certain assemblies from obfuscation. These assemblies will be treated as a Package Artifact and just copied from input-to-output without modification. Any obfuscated assemblies that refer to these excluded assemblies will still be processed correctly.

To do this in the GUI, right-click on the assembly within the package, and select "Exclude assembly from package". Or, if you'd prefer to edit the config file, add the following <option> tag as a child of each relevant <inputassembly> tag:

<option>artifact</option>
Joe Sewell
  • 6,067
  • 1
  • 21
  • 34
  • Thanks for responding. Now it brings a in another question, so i don't want to obfuscate all the dll in a folder as some of the .dll that i am using are thirdparty and they are already obfuscated. So the one's that i am interested can be copied to a different location, obfuscate them using Dotfuscator and copy them back before creating the package? Does any place in the user guide has any sample msbuild task for dotfuscator directory support as an example? – varun7447 Mar 27 '17 at 20:49
  • @varun7447 I've added a note to my answer which I think will answer your comment's first question. I recommend using the method it describes instead of copying some of the DLLs, because then you'll have to configure a custom assembly load path (your obfuscated DLLs will reference excluded DLLs, which are no longer in the same directory). As for your second question about MSBuild support, there's no specific example for this case, but since the package is a feature of the config file, you can just pass the config file's path to the Dotfuscate task's ConfigPath property. – Joe Sewell Mar 27 '17 at 22:06
  • Perfect this is really helpful. Thanks for your prompt response. – varun7447 Mar 27 '17 at 22:12
1

The latest Dotfuscator version 4.41.1 has the latest flag true This will generate the Dotfuscator config file if the file is missing. Also you can add this to the csproj as documented in the latest getting started guide https://www.preemptive.com/dotfuscator/pro/userguide/en/getting_started_protect.html

varun7447
  • 574
  • 1
  • 6
  • 27