Create and use a C# Assembly for SSIS - Page 2

Article Index
Create and use a C# Assembly for SSIS
Page 2
Page 3
All Pages

 

Sign, Build and Deploy

 

Create a GAC signature

 Skip this step if you already have a project-wide GAC signature file available with which to sign your assebly with.

 

Open your console and create a signature file using the sn (StrongName) command, which is installed with the .Net SDK:

 

  1. C:>sn -k Keyfile.snk
  2.  
  3. Microsoft (R) .NET Framework Strong Name Utility  Version 2.0.50727.42
  4. Copyright (c) Microsoft Corporation.  All rights reserved.
  5.  
  6. Key pair written to Keyfile.snk

  

Add the signature file to your project

 Add your signature file to your project just like any other existing file:

Image

 

Sign your assembly

 In addition to adding the file to your project, you also need to specify that you would like to sign your project.  This is done from the Project Properties screen. Select the "Signing" tab, choose to "Sign the assemby" and select your signature file from the dropdown box.

  

Configure the deployment

 At this stage, your assembly is ready to build, but it will not be recognized by SSIS until it is properly deployed in the GAC. 

 

In summary, the deployment consists of 3 steps:

 

  • Signing the assembly (done that above) 

  • Copy the  physical .dll file to the target machine's .NET framework directory

  • Install the assemply to the GAC 

 

The best place to do the last two steps is to script them in the project's Pre- and Post-build  event handlers.

 

Click on the "Build Events" tab and enter the following code for the Pre-build event. The .NET framework directory for Visual Studio 2005 is C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727, for Visual Studio 2008 it is C:\Windows\Microsoft.NET\Framework\v3.5. These are the only directories that SSIS can reference. Bare this in mind for the code below.

 

  1. : Uninstall the previous assembly from the GAC
  2. "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /u $(TargetName)

 

Enter this for the Post-build event:

 

  1. : Install the assembly to the GAC
  2. "C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\gacutil.exe" /i "$(TargetPath)"
  3. : Copy to directory where SSIS can read it
  4. copy "$(TargetPath)" "C:WINDOWSMicrosoft.NETFrameworkv2.0.50727" /y

 

Belts&Braces Note: 

 

I specify the fully-qualfied path for gacutil.exe here since it is not by default on your path. Ideally though, C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin (or wherever gacutil.exe lives, depending on your version of Visual Studio or Microsoft SDK) should be on your path.

 

Build and deploy the Assembly!

 Press Shift-Ctrl-B. (Learn to use  keyboard shortcuts in Visual Studio!)