0

My VS 2010 ASP.Net Web App project would have:

1. Settings file (names of actions, behavior, location of an image in an image cluster, etc.)
2. A javascript containing functions for the actions to use. This file that will get combined in with other javascript files at build time and is OK to overwrite each time as I won't need to customize anything here after it's generated.
3. A CSS file containing information such as the background attribute for a DIV that I'm using as a button to offset into a location within an image cluster.

What I want is:

An addin or some command/entity that I can easily trigger via Visual Studio UI to process the settings and recreate the files containing javascript and css for the actions specified in the settings. The reason I want this is because I'll have 30+ actions and possibly more in the future and don't want to recreate these any time I make changes of how I want them to work and easily be able to add new ones and have the JS and CSS quickly regenerated.

Mark Bath
  • 92
  • 1
  • 8

1 Answers1

1

You can use T4 templates. They can generate any text file based on the template that is written as a mixture of plain text and C#.

alex
  • 12,464
  • 3
  • 46
  • 67
  • Cool, thanks. Here is the link I'm looking at on MSDN on the T4 templates you mention. I think this will do what I need. http://msdn.microsoft.com/en-us/library/vstudio/bb126445.aspx – Mark Bath Jun 20 '13 at 17:54
  • However, the next question is how do I trigger the regeneration when I've changed the "settings file". I will have to go and resave each of the template files to trigger them it seems. Is there a way I can force a resave of those files if a specific settings file is changed that you know of? I ask because I will have probably 3 templates that will generate different files from the same settings and there are so many files in the project it's just a little inconvenient to find them each time and save them. – Mark Bath Jun 20 '13 at 19:03
  • I think this is what I want here (Single File Generator): http://msdn.microsoft.com/en-us/library/bb166508(VS.100).aspx – Mark Bath Jun 20 '13 at 19:39
  • Actually I'll write a small VS addin to listen for save events and then trigger saves on those .tt files so as to regen the code. – Mark Bath Jun 23 '13 at 06:19
  • 1
    You can regenerate code from t4 templates on each build. To do that, special include should be added to project file -http://stackoverflow.com/questions/1646580/get-visual-studio-to-run-a-t4-template-on-every-build?rq=1 – alex Jun 24 '13 at 04:01
  • In VS 2012 which I just upgraded to there is now an option in the "Build" menu to "Transform All T4 Templates" which triggers all of them. Super convenient. – Mark Bath Jun 28 '13 at 06:34
  • I also have used this tool in VS2010 for combining javascript and CSS into single files for performance reasons and it now also will server the purpose of forcing all T4 templates to regenerate code I just found out as I installed the latest version after migrating to VS 2012. http://chirpy.codeplex.com/ – Mark Bath Jun 28 '13 at 06:35