# Monday, November 12, 2007

If you happen to use Dotfuscator by PreEmptive Solutions then you have probably wondered how to integrate this into your automated Team Builds.  They happen to include an MSBuild task for calling the proper command-line functions but don't have much documentation about this feature.

Background Obfuscation Information:  In general, obfuscation prevents reverse engineering of your software by using different techniques to make the MSIL of your .NET compiled application less understandable.  Several different companies use many techniques for doing this including: string encryption, renaming of symbols, control flow manipulation, etc.  If you've ever used Reflector for .NET you know how easy it is to look at reverse-engineered "source code" for a .NET application.

  • Start by putting your Dotfuscator configuration file in the folder that contains your team build script (i.e. TFSBuild.proj) and it to source control.
  • Open up your team build script and edit it.  (Be sure to check it out first.)
    • Start by adding a reference to the proper custom targets file that is provided.  You should have a Dotfuscator Build Machine license installed on the TFS Build Server(s.)  If you got the wrong license version, just ask them for upgrade pricing.

      <Import Project="$(MSBuildExtensionsPath)\PreEmptive\Dotfuscator\4.0\PreEmptive.Dotfuscator.Targets" />

 

    • Next, add a section for the Dotfuscator Properties you will need.  You'll notice we have a keys directory that gets pulled down from source control during the build process.  We keep our strong name key in this direcotry and the keydir directory property is for resigning the assemblies after the obfuscation is complete.

        <!-- Properties for Dotfuscate Task-->
        <
      PropertyGroup
      >
          <
      ConfigPath>$(SolutionRoot)\..\BuildType\Dotfuscator.Configuration.xml</ConfigPath
      >
          <
      InputPath>$(SolutionRoot)\..\Binaries\Release</InputPath
      >
        </
      PropertyGroup
      >
        <
      PropertyGroup
      >
          <
      DotfuscatorProperties
      >
            <
      targetdir>$(InputPath)</targetdir
      >
            <
      keydir>$(SolutionRoot)\Keys</keydir
      >
          </
      DotfuscatorProperties
      >
        </
      PropertyGroup
      >
        <
      ItemGroup
      >
          <
      InputAssembly Include="$(InputPath)\*.dll;$(InputPath)\*.exe" Exclude="$(InputPath)\*.vshost.exe"
      />
        </
      ItemGroup
      >  

 

    • Finally, customize the AfterCompile target by adding the Dotfuscate task with appropriate property settings.  See more information about Customizable Team Foundation Build Targets.

        <Target Name="AfterCompile">
          <!--
      Perform obfuscation steps after assemblies are compiled.
      -->
          <
      Dotfuscate InputAssemblies="@(InputAssembly)" Properties="$(DotfuscatorProperties)" ConfigPath="$(ConfigPath)"
      >
            <
      Output TaskParameter="MappingFile" ItemName="DotfuscatorMappingFile"
      />
            <
      Output TaskParameter="ReportFiles" ItemName="DotfuscatorReportFiles"
      />
            <
      Output TaskParameter="OutputAssemblies" ItemName="DotfuscatedAssemblies"
      />
            <
      Output TaskParameter="SatelliteAssemblies" ItemName="DotfuscatedSatelliteAssemblies"
      />
            <
      Output TaskParameter="DebugSymbols" ItemName="DotfuscatedDebugSymbols"
      />
          </
      Dotfuscate
      >
        </Target
      >
  • Next, take some time to edit your Dotfuscator configuration file.  Notice the properties I am using in my sample project below and what is being set in the Dotfuscator properties collection in the Team Build script above.  Basically, I have just cleared the property values out to make sure that the MSBuild task populates them correctly.

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <!
    DOCTYPE dotfuscator SYSTEM"http://www.preemptive.com/dotfuscator/dtd/dotfuscator_v2.1.dtd"
    >
    <
    dotfuscator version="2.1"
    >
      <!--
    This is application generated code. Do not edit manually.
    -->
      <
    propertylist
    >
        <
    property name="targetdir" value=""
    />
        <
    property name="keydir" value=""
    />
      </
    propertylist
    >
      <
    global
    >
        <
    option>verbose</option
    >
      </
    global
    >
      <
    input
    >
        <
    asmlist
    >
          <
    inputassembly
    >
            <
    option>library</option
    >
            <
    file dir="${targetdir}" name="Shared.Library.dll"
    />
          </
    inputassembly
    >
        </asmlist>
      </
    input
    >
      <
    output
    >
        <
    file dir="${targetdir}\Dotfuscated"
    />
      </
    output
    >
      <
    tempdir
    >
        <
    file dir="${targetdir}\Dotfuscated"
    />
      </
    tempdir
    >
      <
    renaming
    >
        <!--
    <mapping>
          <mapoutput overwrite="false">
            <file dir="${targetdir}\Dotfuscated" name="DotfuscatorMapFile-KeepSecure.xml" />
          </mapoutput>
        </mapping>
    -->
      </
    renaming
    >
      <
    controlflow level="high"
    />
      <
    stringencrypt
    >
        <
    includelist
    >
          <
    assembly
    >
            <
    file dir="${targetdir}" name="Shared.Library.dll"
    />
          </
    assembly
    >
        
    </includelist>
      </
    stringencrypt
    >
      <
    signing
    >
        <
    resign
    >
          <
    option>dontuseattributes</option
    >
          <
    key
    >
            <
    file dir="${keydir}" name="StrongName.key"
    />
          </
    key
    >
        </
    resign
    >
      </
    signing
    >
    </
    dotfuscator>
     
  • That's it.  Finally, just customize it to your heart's content!

 

Feel free to let me know if I can improve this in any way!  I'm always looking to efficiently refactor our Team Build scripts.

 

Ed B.

posted on Monday, November 12, 2007 10:17:54 PM (Central Standard Time, UTC-06:00)  #    Comments [2] Trackback
# Tuesday, January 23, 2007

Microsoft has recently released a version of their application that generates the .NET Framework documentation that we see and love...  You can take a look at it and get more information about the project codename Sandcastle here:  Sandcastle Team Blog

Download the December 2006 CTP here:  Sandcastle - December 2006 CTP Download

Some of the high level features:

Sandcastle produces accurate, MSDN style, comprehensive documentation by reflecting over the source assemblies and optionally integrating XML Documentation Comments. Sandcastle has the following key features:

  • Works with or without authored comments
  • Supports Generics and .NET Framework 2.0
  • Sandcastle has 2 main components (MrefBuilder and Build Assembler)
  • MrefBuilder generates reflection XML file for Build Assembler
  • Build Assembler includes syntax generation, transformation..etc
  • Sandcastle is used internally to build .Net Framework documentation
  • Ed B.

    posted on Tuesday, January 23, 2007 4:00:54 PM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback
    # Wednesday, June 21, 2006

    Tired of installing dll's to the GAC via command prompt or drag and drop to assembly folder?

     

    Well have I got a solution for you. Follow these steps:

     

    1. Create a command file with this information

    @echo off

    @echo *****************************************************************

    @echo ** Add to register

    @echo *****************************************************************

    :Again

    @if .%1.==.. goto Xit

    @dir %1 /b

    @C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\gacutil /i %1

    @Shift

    @goto Again

    :Xit

    @echo *****************************************************************

    @Pause

     

    2. Click start - run and type in "sendto"

    3. Drag and drop the command file to that location

    4. BANG! Now you can simple right click a file and select "Send To" -- "InstallToGac.cmd"

     

    BizTalk guys should really appreciate this one :)

     

    Enjoy,

     

    Ed K.

    posted on Wednesday, June 21, 2006 3:44:26 PM (Central Standard Time, UTC-06:00)  #    Comments [0] Trackback