## Referencing an external DLL from your Tridion C# Compound Templates

November 2nd, 2012 | Posted by in Tridion 2011

In Tridion 2011 we have the opportunity to write C# templates with .NET 4.0.  If you reference an external DLL or another Visual Studio project from your template project the DLL needs to be registered in the GAC.   Follow this short guide to help you get started with registering your external DLLs to reference from your templates.

1. Sign the Assembly in Visual Studio if your external DLL is a Visual Studio project.   Otherwise, you should generate an snk file for your existing external DLL.
http://msdn.microsoft.com/en-us/library/ms247123.aspx

2. Compile Project and copy the DLL to the Tridion Bin folder or another Folder on the CMS server.

3. Use Gacutil to register external DLL.  If you have VS 2010 SP 1 installed it is located in ‘C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools’

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\gacutil.exe" /i file.dll

4. Verify it is in the GAC:

"C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\NETFX 4.0 Tools\gacutil.exe" /l > gac.txt

Open gac.txt in a text editor

5. Compile and Build the Compound Template to deploy the DLL Templates

6. Open Template Builder and Preview the Template.  Use the Logger to write to the log file.

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

## 3 Responses

• Robert, There is no need for exporting your gac to a text file. Just take a look in C:\Windows\assembly .
When updating your assembly; first uninstall the DLL from the GAC, before installing the new version.

• robert curlette says:

Thanks Wouter. That folder works well for assemblies before .NET 4. For the new .NET 4 assemblies take a look in C:\Windows\Microsoft.NET\assembly

• Quirijn Slings says:

If you don’t want to put the dependencies in the GAC, there is an alternative. You can use ilmerge to combine your DLL with the dependent DLLs.
However, I would only recommend this if you are the owner of the dependent DLLs, since you might be breaking copyright laws if you include someone else’s DLLs in your own.

An easy way to do this is with a post build action, like so:

“\path\to\ilmerge” /lib:”C:\Windows\Microsoft.NET\Framework\v4.0.30319″ /t:dll /targetplatform:v4,C:\Windows\Microsoft.NET\Framework\v4.0.30319 /out:”$(TargetDir)$(ProjectName).merged.dll” “$(TargetDir)MyOtherAssembly.dll” “”$(TargetPath)”