?
Solved

I need to reference my object from a T4 template

Posted on 2011-02-18
8
Medium Priority
?
639 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 
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

Tutorials alone can't teach real engineering

So we built better training tools.

-Hands-on Labs
-Instructor Mentoring
-Scenario-Based Tests
-Dedicated Cloud Servers

All at your fingertips. What are you waiting for?

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 …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

764 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