Reputation: 7264
I have a custom dll, which has a class in it, and (for simplicity's sake) there's a method on it which'll return a string.
I have a project, which references said dll, and I want to use a (not preprocessed) T4 template in that project, which calls said method. I've tried this:
<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="MyDLL.dll" #>
<#@ output extension=".cs" #>
<#
var template = new MyDLL.MyNamespace.MyClass();
this.Write(template.Run());
#>
I got the following errors:
Error 14 Compiling transformation: Metadata file 'MyDLL.dll' could not be found
Error 13 A namespace cannot directly contain members such as fields or methods
even if MyClass.Run() is simply a return "//hello";
Upvotes: 10
Views: 7466
Reputation: 13168
(Note: all of this applies to VS2013. Might be different with other versions.)
First, use $(TargetDir)
to find the file in your output path.
Ex: <#@ assembly name="$(TargetDir)MyDLL.dll" #>
Second, it seems that the template generator runs before references are copied to the output folder. So if you haven't successfully built at all yet, or haven't built at least once with the new reference added to the project, then the .dll will not be there.
And in fact it will never be there till you do successfully build, and if you're getting an error from the template generator that the reference can't be found, you'll never successfully build, and you're stuck.
The way to get out of this situation is to either exclude the template temporarily, get your project to build, (which will copy references), and then add it back; or else manually copy the .dlls yourself to the directory that it's complaining about. Once things are building, they should stay building.
(Since the template generator runs before references are copied, I suspect there would be a similar issue involving new code. If you add new code to a library, and make use of it in your template before building, you would get stuck with the template not being aware of the new code, which makes it throw an error, which makes your build not succeed, so it doesn't get the new version, and you're stuck again.)
(You also should end up in this situation whenever you clean or rebuild your project, but I don't seem to have that happen very often, so there may be more to this than I realize.)
Upvotes: 0
Reputation: 4131
Seems like Your problem:
Error Compiling transformation: Metadata file 'dotless.Core' could not be found
It's due to compatibility break described here:
Upvotes: 8
Reputation: 27107
I had the very same problem only yesterday, we've got a solution level Binaries folder, so the the following worked for me $(SolutionDir)Binaries\Assembly.dll
.
However, depending on where the assembly is located, you may be able to use a project relative path by using the $(ProjectDir)
directive...
Upvotes: 8