1

I want to use the SquishIt nuget package inside and MVC3 application that is running on Windows Azure. I'm using SquishIt for CSS and JS combination and minification.

In my Views/Shares/_Layout.cshtml I have the following lines:

@MvcHtmlString.Create(
    Bundle
    .Css()
    .Add("~/Content/templates/style.css")
    .Add("~/Content/market.css")
    .Add("~/Content/jquery-ui-theme/jquery-ui-1.8.17.custom.css")
    .ForceRelease()
    .Render("/Cache/combined-css_#.css"))

This results in an

"System.IO.IOException: Unable to open file"

I found something here http://www.bondigeek.com/blog/2011/03/22/all-is-quiet-not-on-the-azure-front/ but this is actually not what I want. In general it should be possible for SquishIt to write on the disk of the Azure VM, but probably the directory is wrong or the security rights are insufficient. Any idea?

x10
  • 3,820
  • 1
  • 24
  • 32
hydr
  • 408
  • 3
  • 10
  • 1
    Do all paths exist? This error is generally because SquishIt will not create a directory if it does not exist, it will just throw an IO error. Make sure your /Cache/ directory exists on the server as well as all your included files. – Paul Feb 03 '12 at 17:50

2 Answers2

4

In Azure VM, you cannot write to file system directly. You have to configure SquishIt to keep bundles in memory.

See this page for more details: Using SquishIt programmatically without the file system

Miroslav Bajtoš
  • 10,667
  • 1
  • 41
  • 99
2

You can use It on azure but you need to add a Start-up Script in the web role that will set proper Permission on the Directory that you write to:

Those are the Steps:

  1. Add a new folder to the web project , I prefer to call it App_Startup
  2. Add new Bat File called enableWritePermissions.cmd
  3. Add the Permission Command: icacls %~dp0..\scripts /grant "NETWORK SERVICE":(OI)(CI)RX
  4. Add a start-up Script to the web role by adding the ServiceDefinition.csdef of the Azure Project in the Sites Tag <Startup> <Task commandLine="App_Startup\enableWritePermissions.cmd" executionContext="elevated" taskType="background" /> </Startup>

That's all , you have a Write permission in the \scripts directory and you can use the Minimization freely.

OBender
  • 2,492
  • 2
  • 20
  • 33
  • Thanks, that's also an interesting approach. I went with the in-memory approach, but setting write permissions could come handy in other scenatios, too. – hydr Nov 28 '12 at 15:27