2

Simple question, could'nt find a straight answer. How can I modify the output file name of a T4 Template?

I'm using a T4 Template to bundle and minify all my javascript files. Now I want to include the current Assembly Hashcode in my filename. But how can I access this filename?

A workaround would be to rename the ouput file after generating it but this doesnt't seem nice to me.

iappwebdev
  • 5,880
  • 1
  • 30
  • 47
  • Is T4 really the best tool to bundle and minify js? – Roman Jun 20 '12 at 12:53
  • Well, it's not only for bundling and minifying, I was just curious and couldn't find an asnwer. But anyway what would be your suggestion regarding a) bundling and b) minifying js? – iappwebdev Jun 20 '12 at 13:01
  • There's a similar question here: [Is there a .NET library for minifying Javascript?](http://stackoverflow.com/questions/8567070/is-there-a-net-library-for-minifying-javascript). [Scott Hanselman](http://www.hanselman.com/blog/TheImportanceAndEaseOfMinifyingYourCSSAndJavaScriptAndOptimizingPNGsForYourBlogOrWebsite.aspx) talks about a few tools to minify/pack JS and CSS. When ASP.NET 4.5 comes out, it looks like some of that will be [built into the framework](http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx). – Roman Jun 20 '12 at 13:08
  • Admittedly, the ASP.NET 4.5 stuff isn't going to be useful to you today, but may be worth being aware of for if/when you upgrade your site. – Roman Jun 20 '12 at 13:10

1 Answers1

0

You need to do something called auto-versioning, and this is usually done by URL rewriting. The physical files are not actually renamed.

See this question for details on javascript and css auto versioning:

How to force browser to reload cached CSS/JS files?

Note that if you use templates to generate a different physical file for every time you generate a file then you will lose a lot of benefits of source control (revisions etc), and you will end up with an unmanageably large set of files on disk.

Community
  • 1
  • 1
JK.
  • 21,477
  • 35
  • 135
  • 214