This article isn’t a complete tutorial on how to code CoffeeScript, but it will focus on how to use CoffeeScript with ASP.NET. First, you’ll need CoffeeScript and Visual Studio 2010. There are a couple of ways to get CoffeeScript installed and running on your machine. One way is to install CoffeeScript as a Node.js utility. However, installing Node.js is beyond the scope of this article as I’ll be focusing on running CoffeeScript inside Visual Studio.
Using CoffeeScript Inside Visual Studio
Once you’ve installed Web Workbench, open Visual Studio and start a new web site project. Opening the New File Dialog, will show you the new CoffeeScript templates, seen below.
Add a .coffee file named coffeedemo.coffee. Once the file is added, insert the following code, which displays a message when the page loads. Don’t worry about the syntax right now. I’ll cover that in an upcoming series.
display = -> alert 'I am running from CoffeeScript!' window.onload = display()
Malcolm Sheridan is a Microsoft awarded MVP in ASP.NET, ASPInsider, Telerik Insider and a regular presenter at conferences and user groups throughout Australia and New Zealand. Follow him on twitter @malcolmsheridan.