How To: Integrate Code Protection into the Build Process with Post-Build Events

With Microsoft Visual Studio 2005 and later, you can define post-build tasks for your development projects. This functionality allows you to integrate Microsoft SLP Code Protector into your build process. 

The following sections provide step-by-step instructions for the integration. 

 

Note: Command-line protection cannot be applied if a generic Permutation is used. You must first create a private Permutation. 

To Create an SLP Code Protector Configuration File 

  1. Open SLP Code Protector.
  2. Click the Project tab, and then click View.

Bb896224.SLPCodeProtector(en-us,MSDN.10).jpg

  1. Add the modules, and select the methods you wish to protect. Define all necessary settings for the methods.
  2. The settings apply to the entire project, the application, and the methods selected for protection. Settings are displayed in the right portion of the page in the Project view. For more information about selecting the settings, refer to the SLP Code Protector User Guide.
  3. Click File, and then click Save Project As…
  4. Enter a file name with a .SLMCfg extension, for example, ProtectionSettings.SLMCfg. Click Save. This creates a configuration file called ProtectionSettings.SLMCfg.

 

To Protect Code in Debug and Release Versions

  1. Open SLP Code Protector.
  2. Click File, and then click SaveAs to add the SLP Code Protector configuration file to the project folder.

Bb896224.HowToIntegrateCP1(en-us,MSDN.10).jpg

  1. Open the project in Visual Studio. If you want to protect both Debug and Release versions of your builds, you must create two copies of the configuration file. Name one of the files Release.SLMCfg and the other Debug.SLMCfg.

Bb896224.HowToIntegrateCP2(en-us,MSDN.10).jpg

  1. Change the values for InputDir, OutputDir, and ModuleName to the appropriate directories.

Bb896224.HowToIntegrateCP3(en-us,MSDN.10).jpg 

Bb896224.HowToIntegrateCP4(en-us,MSDN.10).jpg

  1. Save your changes.

 

To Create A Custom Post-Build Action

  1. Open the Properties window of your project.

Bb896224.HowToIntegrateCP5(en-us,MSDN.10).jpg

  1. Open the Build Events tab.

Bb896224.HowToIntegrateCP6(en-us,MSDN.10).jpg

  1. Add the following post-build event.

"%Programfiles%\Microsoft SLP Code Protector\Microsoft.Licensing.ProtectCmd.exe" "$(ProjectDir)$(ConfigurationName).SLMCfg" 

Bb896224.HowToIntegrateCP7(en-us,MSDN.10).jpg 

  1. Build the project. Verify that protection has succeeded by reviewing the results in the Output window.

Compile complete -- 0 errors, 0 warnings 

TestBuild -> C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\bin\Debug\TestBuild.exe 

"%Programfiles%\Microsoft SLP Code Protector\Microsoft.Licensing.ProtectCmd.exe" "C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\Debug.SLMCfg" 

Performing code transformation... 

Embedding required resources... 

Preparing output directory... 

Writing protected files to "C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\bin\Debug.Protected" 

Copying miscellaneous files from input directory "C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\bin\Debug" to output directory "C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\bin\Debug.Protected" 

Writing permutation-specific redistributable files to "C:\Users\testuser\Documents\Visual Studio 2005\Projects\TestBuild\TestBuild\bin\Debug.Protected" 

Protection succeeded 

========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ========== 

 

See Also 

How To: Apply Command-Line Application Protection with SLP Code Protector 

What do you think about this topic? Send feedback!