[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I need to reference my object from a T4 template

Posted on 2011-02-18
8
Medium Priority
?
647 Views
Last Modified: 2012-05-11
I can not seem to reference my object, in the same project, from my T4 template.

Please show the line of code, starting with <#@ that I need to import the namespace.

I assume that once I am able to instantiate a single global object, I can reference it anywhere in the T4 template.

newbieweb
0
Comment
Question by:newbieweb
  • 4
  • 4
8 Comments
 
LVL 3

Expert Comment

by:chandra_darbha
ID: 34931173
T4 templates are independent and they can't access anything directly from other classes. If you need an object instantiated elsewhere you need to pass that object as an argument to the template. For that you need to define the argument in the template and also add it to the arguments list when invoking the template.

Syntax for declaring argument in T4 -
<#@ property processor="PropertyProcessor" name="ClassName" type="System.String, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" #>

P.S: you need to provide the Fully qualified assembly name in the "type" attribute.

In C# you should pass the arguments as shown below -

var arguments = new Dictionary<string, PropertyData>();
arguments.Add("ClassName", new PropertyData("MyClass", typeof(string)));
string currentDirectory = Directory.GetCurrentDirectory();  
TemplateHost host = new TemplateHost(currentDirectory, arguments);  
host.TemplateFile = Path.Combine(currentDirectory, "MyTemplate.tt");

Thanks,
Chandra
0
 
LVL 3

Accepted Solution

by:
chandra_darbha earned 2000 total points
ID: 34931213
Incase if you want to instantiate the object within the T4 template itself then you need to import the assembly and the namespace and then use the Class for instantiation.

<#@ assembly name="Assembly.dll" #>
<#@ import namespace="MyNamespace" #>

Thanks,
Chandra
0
 

Author Comment

by:newbieweb
ID: 34953296
Actually, I have been trying (unsuccessfully) to get past the assembly command:
<#@ assembly name="Assembly.dll" #>


how do I find the name of the acceptable DLL? It's built in this same solution and I even located the T4 Template in the same folder as the file I need, but nothing's worked.

Please help point out the full assembly name, based on the attached project view.

Thanks,
newbieweb


 T4 Template Namespace Problem
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
LVL 3

Expert Comment

by:chandra_darbha
ID: 34977400
Please post the error you are getting and the T4 code.

Thanks,
Chandra
0
 

Author Comment

by:newbieweb
ID: 34979358
Compiling transformation: Metadata file 'RDDBWEB2.RDDBWebAdmin.dll' could not be found      

I do not know what to use in place of Assembly.dll.

<#@ assembly name="Assembly.dll" #>
<#@ import namespace="MyNamespace" #>
0
 
LVL 3

Assisted Solution

by:chandra_darbha
chandra_darbha earned 2000 total points
ID: 34980418
From what I see in the screenshot above and assuming Visual Studio default namespace naming convention below is what I am guessing. Try this. if it doesn't work out then I would need more details.

<#@ assembly name="RDDBWebAdmin.dll" #>
<#@ import namespace="RDDBWebAdmin.Models" #>

Thanks,
Chandra
0
 

Author Comment

by:newbieweb
ID: 35007330
RDDBWebAdmin.dll could not be found. I have had this problem endlessly.

Where does this definition fit into this?
<#@ template language="C#" debug="false" hostspecific="true"#>
<#@ include file="EF.Utility.CS.ttinclude"#>
<#@ output extension=".cs"#>

what's the sequence?
0
 

Author Closing Comment

by:newbieweb
ID: 35019207
Thanks.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

872 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question