title: Dynamic Stylesheets Using Razor
body: <p>How can I use Razor in CSS files?</p>
  
  <p>I'm using <a href="https://github.com/Antaris/RazorEngine" rel="nofollow noreferrer">Razor View Engine</a> for some time and I was curious about using it on style sheets. I can use Razor in <code>&lt;style&gt;</code> blocks of <strong>.cshtml</strong> files but I was wondering if I can use it in external <strong>.css</strong> files also (would like to have a <strong>.cscss</strong> format). So I googled it and found two things:</p>
  
  <p>The first one is <a href="http://lesscss.org/" rel="nofollow noreferrer">LESS</a>: "The dynamic stylesheet language". It seems easy-to-use and powerful with all the features but I need Razor-C#, really.</p>
  
  <p>The second is <a href="http://www.codeproject.com/Articles/171695/Dynamic-CSS-using-Razor-Engine" rel="nofollow noreferrer">Dynamic CSS Using Razor Engine</a>, a CodeProject article which is more like what I want but it has no caching or pre-compiling support (by "no support" I meant the writer didn't mention these aspects). I also would like to have some syntax highlighting in Visual Studio but this is secondary.</p>
  
  <p>So, how can I write Razor in CSS files with minimum performance cost and preferably with syntax highlighting?</p>
  
  <ul>
  <li>Is there a "more complete" project for that?</li>
  <li>Can I improve the above project to achieve caching/compiling? If so, how? </li>
  </ul>
  
  <p><em>As a side note:</em><br />
  I found a project called <a href="http://djsolid.net/blog/razorjs---write-razor-inside-your-javascript-files" rel="nofollow noreferrer">RazorJS</a>. It's like the Javascript version of the same thing I want for CSS with its caching support. I'm mentioning this just to clarify my needs. I don't need to use Razor in Javascript currently but I guess if I make it out with CSS, doing the same thing with Javascript wouldn't be too hard.</p>