assembly directive requires full path to project assemblies


I'm trying to reference a solution generated assembly from a T4 template that I'm invoking from the Package Manager Console using the pattern of .ps1 and .cs.t4 template files created by "scaffold customscaffolder".

If I add an assembly reference like this:
<#@ assembly name="C:\full\path\to\solution\project\bin\foobar.dll" #>
it works. But that won't work for anyone else...

If I attempt this:
<#@ assembly name="$(ProjectDir)bin\foobar.dll" #>
it fails to find the assembly. (Yes the assembly is in the bin subfolder of the project selected as the "Default Project" for the Package Manager Console.

I recognize this may be a T4Scaffolding package issue. Or just me being clueless.
Any help in understanding how best to do this would be appreciated.


TonesNotes wrote Feb 21, 2014 at 2:53 PM

The short answer is:
<#@ assembly name="foobar" #>
Will work for any assembly referenced by your project. Do NOT add a ".dll" to the end.

The longer answer is:

The T4Scaffolding "scaffold" command uses its own DynamicTextTemplatingEngineHost to process the template. This host doesn't provide access to the Visual Solution macros. Instead, it implements its own ResolveAssemblyReference method which among other things looks through a list of "FindableAssemblies" which it initializes by enumerating the assemblies referenced by your project.

The key is that an "assembly" directive will match this list only if the assembly FullName (includes path) or Name (no path, no extension) match.

jeepdude2009 wrote Jun 12, 2014 at 5:25 PM

I've tried just using the assembly name without the ".dll" extension and it still cannot find the assembly. I've also tried signing the assembly (as suggested elsewhere) with no luck. I don't understand how it can't find it when it's part of the same solution. The only thing that works is the full path, which (as mentioned) is not very team-friendly. The project/assembly that scaffolding can't find is my Resources project which is just the resource files required for internationalization.