1

In my t4 template file, I have the following line which definitely will break in build mode.

<#@ assembly name="$(SolutionDir)\MYNAMESPACE.MYLIBRARY\bin\debug\MYLIBRARY.dll"> #>

In order to run this template from my asp.net web project, I have to hard code bin\debug in the above path.

Originally I had the following line,

<#@ assembly name="$(SolutionDir)\MYNAMESPACE.MYLIBRARY\$(OutDir)\MYLIBRARY.dll"

>

but having (OutDir) did not work because my web project outpath is bin\ folder and it kept looking for MYLIBRARY.DLL in bin folder as opposed to bin\debug folder. and I got the following error:

Compiling transformation: Metadata file mynamespace.mylibrary\bin\mylibrary.dll' could not be found

I can not update my web project output path property to bin\debug as opposed to bin\ because then the web project just would not run as explained in the article.

Q.. how can I get rid of hard coded bin\debug path in t4 template file??

Community
  • 1
  • 1
dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200

2 Answers2

2

You can use the ProjectDir and OutputPath variables to accomplish this, regardless of your project or build configuration.

<#@ assembly name="$(ProjectDir)$(OutputPath)MyLibrary.dll" #>

carlin.scott
  • 6,214
  • 3
  • 30
  • 35
1

I updated the first line in my t4 template file as follows:

<#@ assembly name="$(SolutionDir)\MyNameSpace.MyLibrary\bin\$(ConfigurationName)\MyLibrary.dll"

>

Since, t4 template is only executed when I am developing software in debug mode, and I am using it to generate classes, its okay to even hard code it as bin\debug. Once class is generated using t4 template, its checked in and ready to be deployed to build machine.

dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200