This article offers guidance on how to effectively integrate protection into an automated build script. Previously, the main documented technique for integrating protection into an automated build script was via Post Build Steps. Code Protector versions 3.0.1908 and later provide an MSBuild task that intercepts binaries (DLLs or EXE's) immediately after compilation in order to protect them as an integrated part of the build process.
Background
Until V3.0.1908, the main documented technique for integrating protection into an automated build script was via Post Build Steps. This can be cumbersome in many ways. In the case of ClickOnce, another key issue is that one cannot simply transform the DLLs to protect the final binaries prior to deploying the files as the manifest contains checksums that would need updating.
New MSBuild Target
Code Protector versions 3.0.1908 and later provide an MSBuild target that intercepts binaries (DLLs or EXE's) immediately after compilation in order to protect them as an integrated part of the build process.
This will apply to any project that:
- Has a SLMCfg stored alongside the project (.vbproj/.csproj) file named:
<ProjectName><.Configuration><.Platform>.SLMCfg
<ProjectName><.Configuration>.SLMCfg
<ProjectName>.SLMCfg
- Has the conditional compilation (i.e., #define) symbol SLPS_PROTECT defined (referred to as DefineConstant within MSBuild properties) for the active build configuration. (NB For SLPS_PROTECT to be detected correctly all symbols must be delimited by semi-colons - the Visual Studio project system also accepts spaces and commas)
Prerequisites
You must first
- Download and install the Code Protector SDK and Permutation file - see Download/Install Code Protector
- Create a Code Protector Configuration file - see Create Code Protector Configuration File
You should not need to make any changes to your .csproj/.vbproj files in order to use the integrated protection. On installation of the Code Protector SDK, the Slps.Protector.targets file is automatically imported in all builds via a hook inserted into
%ProgramFiles%\MSBuild\<msbuild version>\Custom.After.Microsoft.Common.targets.
If you wish to explicitly ensure that the target is included for a specific project, one can add an import of the same targets file to your project by adding the following before </Project> in your .csproj/.vbproj etc. file
<Import Project="$(MSBuildExtensionsPath)\InishTech\Slps.Protector\Slps.Protector.targets" />
Using MS Build Task
To use the MSBuild task the following steps should be carried out:
- In Visual Studio,
- Go to Project|<ProjectName> Properties|Build|Conditional compilation symbols:
- Add ;SLPS_PROTECT
Please ensure that all symbols are delimited by semi-colons (;) - SLPS_PROTECT will not be correctly detected if any other delimiter is used e.g. space, comma.
- Create a configuration (.SLMCfg) file as covered in Create Code Protector Configuration File
- Save the configuration file to the same folder as your project (.csproj/.vbproj) file.
You can do this just for the Release configuration if you wish - however if you are doing any Runtime customizations i.e., referencing the Runtime DLL, be sure to reference the Permutation DLL too as all three of the Runtime DLLs need to be present alongside each other even when the code is not protected.Troubleshooting
In order for this approach to work the following needs to be in place:
- The MSBuild integration needs to be installed (versions 3.0.1908 and later of the Code Protector SDK provide this by default) and C:\Program Files (x86)\InishTech SLP Code Protector\Slps.Protector.targets should exist
- Check the Slps.Protector.targets file is included. This can be via either:
- Normal automatic inclusion into all builds via: %ProgramFiles$\MSBuild\<msbuild version>\Custom.After.Microsoft.Common.targets
- Adding an explicit import of the targets file to your project by adding the following before </Project> in your .csproj/.vbproj etc. file
<Import Project="$(MSBuildExtensionsPath)\InishTech\Slps.Protector\Slps.Protector.targets" />
- In Visual Studio 2008 or 2010, turn on detailed logging via Tools|Options|Projects and Solutions|Build and Run|MsBuild project build output verbosity. You can quickly locate Code Protector related activity by searching for "Slps_Protect" in the build output (View|Output)
- Go to Project|<ProjectName> Properties|Build|Conditional compilation symbols:
Comments
0 comments
Article is closed for comments.