简体   繁体   中英

MVC T4 Template: Change output file name

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 Hashcodein 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM