2

I have a problem when I'm building my project using MsBuild. I forced to generate file from T4 Template before every build. I have line like this in my T4 Template file:

IServiceProvider hostServiceProvider = (IServiceProvider)this.Host;

I'm getting exception that i cannot cast type 'Microsoft.VisualStudio.TextTemplating.CommandLine.CommandLineHost' on type 'System.IServiceProvider'. When I right click my tt file and choose 'Run custom tool' it is working ok. What is wrong here? How can I make it work?

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
Paweł Reszka
  • 1,557
  • 4
  • 20
  • 41
  • This just means you don't have any errors in the T4 template that would cause it not to run. That does not guarantee that the code it generates will be valid code. Don't worry about the T4 template at the moment (you'll update it once you figure out your problem), but rather what is wrong with the generated code. – Lee O. Jan 20 '14 at 15:00
  • No, the code is all right. I'm using it for about a month. I just needed to use MsBuild script to build it. And now when I'm building it from Visual Studio Command Prompt I'm getting this error. Do you have any idea why I can't build it in this way? – Paweł Reszka Jan 20 '14 at 15:15
  • I didn't quite understand the question the first time apparently. It looks like you can't do what you are attempting to do: http://stackoverflow.com/questions/14409368/t4-template-will-not-transform-with-build – Lee O. Jan 20 '14 at 15:33

0 Answers0