Monday, 11 January 2010

Easy-peasy web dependencies using T4 templates

Sometimes you want to include one or two files from a project somewhere on the internet, and you want to be able to get the latest version without having to track it down every time. By simply creating a t4 template which downloads the latest version you can include a file and get the latest version whenever you have to feel like it.

e.g. To include the very handy Mono.Options file, a library for writing command line parameters, just create Mono.Options.tt with the contents:

<#@ template language="C#v3.5" #>
<#
    var wc = new System.Net.WebClient();
	var src = wc.DownloadString("http://anonsvn.mono-project.com/viewvc/trunk/mcs/class/Mono.Options/Mono.Options/Options.cs?view=co");
	this.Write(src);
#>

Just open the .tt file and hit save to get the latest version!

Submit this story to DotNetKicks

1 comments:

zproxy said...

Ha! But my jsc compiler could apply any IL rewrite it likes on the compiled code. :) Including security checks!

Be sure to check out my latest post :)

Post a Comment