T4 Generation: Where does VsNamespaceSuggestion() pull from?
Asked Answered
T

4

25

Does anybody know, in a .tt file, where code.VsNamespaceSuggestion() gets its namespace from?

I'm having an issue where I had to change a solution's namespace, and I swear I've changed it everywhere (folder names, filenames, project names, project properties, assembly info, etc). But when the .tt file runs, it always puts the old namespace back in its generated classes. I'm told it comes from the EF model, but I see nothing in there that shows a namespace (either in the designer/properties or by opening the .edmx file in NotePad).

Any thoughts? For a hack, I'm simply overriding it in the next line with the namespace I want:

string namespaceName = code.VsNamespaceSuggestion();
namespaceName = "Desired.Namespace"; //HACK:
Twentyfour answered 10/5, 2011 at 16:14 Comment(0)
B
59

Just had this exact problem, and the solution I discovered wasn't mentioned here, so I thought I'd help anyone that came across this article in a search.

Click on the code-generation *.tt file that is generating your entities. In the properties pane, set the Custom Tool Namespace to the namespace you would like generated. Mine was blank, so T4 was generating the namespace from the default project namespace + folder heirarchy.

Brunet answered 16/6, 2011 at 19:42 Comment(0)
V
3

The T4 host in Visual Studio pulls this from the CallContext property bag, using the name "NamespaceHint".

That value is populated by the standard T4 custom tool (SingleFileGenerator) mechanism using the default namespace specified for the custom tool, which is either derived from the project default namespace and the path from the project root to the tt file or is explicitly specified in the property grid below the custom tool specification (as @mattkab says in his answer)

If you're using the T4 service from code, you can populate this by setting up CallContext yourself.

Vicennial answered 24/4, 2012 at 22:29 Comment(0)
J
3

Just modify the properties of *.tt files as following image, and effective immediately.:

Default is empty

Joy answered 25/7, 2015 at 11:4 Comment(0)
T
1

I think I've fixed the problem. I re-checked all projects' Default Namespaces after sra's comment just to make sure, but everything was indeed correct.

"Find All In Files" didn't turn up anything. I used a little free tool called Agent Ransack, and it found a .csproj file with a tag named , which had the old namespace in it. I changed that, and THAT's what fixed it.

AR also found the old namespace in a bunch of bin/Debug files (abosluteFileList and cache files). I deleted all of those files so they would be regenerated with the new namespace. I have no idea if that had any effect.

AR also found instances in my .suo file. Since the problem seems to be fixed, I didn't delete that file (you can't edit it in NotePad, unfortunately).

Twentyfour answered 13/5, 2011 at 16:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.