Visual Studio Development Bookmark and Share   
 index > Visual Studio Guidance Automation Toolkit > Assembly reference in .t4 file
 

Assembly reference in .t4 file

Hi

I am using a .cs.t4 file, in the property processor section i have added

<#@ assembly name="System.dll" #>

<#@ assembly name="System.DirectoryServices.dll" #>

<#@ Import Namespace="System.DirectoryServices" #>

<#@ Import Namespace="System.DirectoryServices.ActiveDirectory" #>

and also after this section i mentioned

using System.DirectoryServices;

using System.DirectoryServices.ActiveDirectory;

but i dont see, the code that used the DirectoryServices.dll isnot active,after the t4 template has been transformed. After going throughly I found that it should be added in the references section of the .csproj XML

like this for the projectwhich we add this .cs file,

<ItemGroup>

<Reference Include="System"/>

<Reference Include="System.Data"/>

<Reference Include="System.DirectoryServices"/>

<Reference Include="System.Xml"/>

</ItemGroup>

then i Could able to see that it works fine. My question is that with using <#@ assembly namespace=".." #> automatically the reference will not be added to the references section of the project , does we need to this manually.

Please clarfiy me..

thanks

satish

satish padidem  Sunday, January 06, 2008 11:12 AM
Hi Satish, I'm not sure if I'm following you but the assembly and Import directives will not add the references where the template is being unfolded. These directives are necessary if you need to use those assemblies inside you t4's code blocks.

So the <#@ assembly ... #> directive will not add the reference in the project where the template is being unfolded.

Hope this clarify the directive usage.
-Adrian
Adrian Alonso  Wednesday, January 09, 2008 11:49 AM
Hi Satish, I'm not sure if I'm following you but the assembly and Import directives will not add the references where the template is being unfolded. These directives are necessary if you need to use those assemblies inside you t4's code blocks.

So the <#@ assembly ... #> directive will not add the reference in the project where the template is being unfolded.

Hope this clarify the directive usage.
-Adrian
Adrian Alonso  Wednesday, January 09, 2008 11:49 AM

Hi Satish,

code to use assemblies in the T4 Template:

If you want to user the System.dll in your T4 template, below need to be included in yout T4 template:

<#@ Assembly name="System.dll" #>

<#@ Import Namespace="System" #>

Code to have assemblies that would be used in the generated code:

For this simply you need to add the assemblies with using statement. If you want to user the System.dll, it would be

using System;

using System.Data;

using System.Configuration;

using System.Collections;

NOTE: If you are refering the assemblies with using statements in the code file, make sure that you have taken reference to those aseemblies from GAC or other folders. If not, even though you write the using statements, the code will not be active.

Regards,

-Noor

Noor Mohammed  Wednesday, January 09, 2008 12:52 PM

You can use google to search for other answers

Custom Search

More Threads

• Calling a recipe inside another recipe???
• GAT: unexpected error loading template...
• GAX/GAT for VS 2005-2008 default templates removed
• Generating custom BAL after using repository factory
• Wizard size and colors
• The specified '8.0Exp' registration setting is not valid
• Can't see item templates for WebApplication projects
• Creating a non C# project template using GAT
• Best Practices for GP?
• Best practice for Testing