T4 Assembly Directive with Relative Path in Website Project?
Asked Answered
M

4

8

I have a website project in Visual Studio and I'm trying to reference some assemblies from the bin directory of the site.

So far, the rooted path is the only one that works:

<#@ Assembly Name="C:\Code\Web Solution\Website\bin\My.dll" />

Other people mentioned using msbuild variables, but this doesn't work for me:

<#@ Assembly Name="$(SolutionDir)Website\bin\My.dll" />

and I'm pretty sure relative paths just flat out don't work (My tt file is in a subfolder in App_Code):

<#@ Assembly Name="..\..\bin\My.dll" />

Without using the rooted path, is there any way to make this work in the context of a website project?

Mugger answered 25/7, 2013 at 14:33 Comment(0)
T
7

GAC or absolute paths are required for assembly references in T4 Templates.

However you can use relative paths from a known path:

eg:

$(SolutionDir)\..\..\packages\Pluralizer.0.3.0.1\lib\net40\Pluralize.dll
Thorrlow answered 9/2, 2015 at 9:19 Comment(0)
S
1

is dll exist on running T4?

I create MvcApplication1 with MVC 4 Application template.

create App_Code directory and create tt.

<#@ assembly name="$(ProjectDir)\bin\MvcApplication1.dll" #>

build the project and run it succeed to trasnform

but clean the build and run it results fail.

because, clean removes build output dll ,dll not existing on specified path.

Sojourn answered 25/7, 2013 at 15:22 Comment(4)
Well this is a website project... so this particular DLL is always in the bin, and never gets cleaned.Mugger
To be more specific, the project is a "website project", so I think that is why those macros/variables for the project/solution directory doesn't work.Mugger
oh sorry, I testing with website project now. but I can not found the dll on bin. repro steps Create website project, add Bin directory and App_Code Directory, create Class1.cs on App_Code,Sojourn
not work. I write a project property enumeration gist.github.com/kazuk/6085409 ,results Website project don't have ProjectDir property, and founds FullPath property, but $(FullPath) doesn't work on me. It looks for me, macro expanding is not work on Website project.Sojourn
R
0

I think you can find it using the envDTE (Example here to navigate the project to find the bin directory.

Russell answered 25/7, 2013 at 14:38 Comment(0)
D
0

Try using slashes instead of backslashes when defining relative paths:

<#@ Assembly Name="../../bin/My.dll" />
Detroit answered 25/7, 2013 at 14:42 Comment(2)
@JohnBubriski it is strange since we are using the relative paths with backslashes and it is working. Maybe, inside an Assembly node it is not working this way.Detroit
Are you using a website project, or a web application project?Mugger

© 2022 - 2024 — McMap. All rights reserved.