Accessing Custom .NET Assemblies in SSIS 2008 Script Tasks

In: SSIS
Written by: Taylor Gerring


14 Oct 2009

If you need to access a custom .NET Assembly from an SSIS Script Task, Microsoft doesn’t make things very easy – but it’s still possible with a little setup. This is a great way to introduce custom data types or some new functionality without having to replicate that code in a new environment.

The Setup

  • Windows 7 64-bit
  • Visual Studio 2008
  • SQL Server 2008 64-bit

The Process

  1. Create a signing key (See also, How to: Create a Public/Private Key Pair)
    1. Open Visual Studio 2008 command Prompt – the regular command prompt will not work
    2. Change to a friendly directory: cd %userprofile%\Desktop
    3. Create the key file: sn -k key.snk
  2. Sign the assembly – There are a few ways to do this, but I found this to be the easiest. If you want to sign it some other way, check out How to: Sign an Assembly with a Strong Name
    1. Right-click the Project
    2. Select “Properties”
    3. Navigate to the “Signing” tab
    4. Browse to strong name key file (which was created in the previous step)
    5. Recompile the project
  3. Copy the re-compiled assembly to your GAC
    1. gacutil -i “C:\Path\to\CustomAssemblyName.dll”
  4. Copy assembly to “%programfiles(x86)%\Microsoft SQL Server\100\SDK\Assemblies”
  5. Add reference in script task. Repeat this for every Script Task you want to access this assembly from
    1. Right-click References
    2. Click “Add Reference…”

      Add Reference...

      Add Reference...

    3. On the .NET tab, scroll to find your assembly
    4. Press “OK”
    5. The Assembly should now appear under the References list
  6. Add a reference to the assembly in code, at the top
    1. (C#) Using CustomAssemblyName;
    2. (VB.NET) Imports CustomAssemblyName
  7. You should now have full access to the imported DLL

Caveats

This method works pretty well, but deployment isn’t exactly seamless – you’ll have to repeat this for each server and re-register & copy the DLL separately for any updates. Additionally, there is no way to globally add the assembly reference to the entire project or package. Instead, you’ll have to repeat step 6 (adding the reference) for every Script Task.

2 Responses to Accessing Custom .NET Assemblies in SSIS 2008 Script Tasks

Avatar

Marcelo

April 25th, 2010 at 8:13 am

My problem was, every time I edit my script task, my dll`s references disappear. So, I had to do step 5 again. The work around was:

Go to script task properties, change the delay validation to true.

This article is great!
Thanks

Avatar

Sid

April 28th, 2011 at 7:53 pm

Marcelo> Thanks for that tidbit! I had the same problem, this helps a lot.

Taylor> Much thanks for the write-up, I agree, it’ll be nice in the future if you can add a reference to a project/task. Let’s cross our fingers.

Comment Form

@TaylorGerring


Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.
Stop SOPA
Unless specified otherwise, this website is licensed under a Creative Commons Attribution-ShareAlike 3.0 United States.