9

I have an ASPNET mvc project using both Nuget and Bower for dependencies. Now I need to either trigger bower to install components upon deployment or as fallback include the packages by allowing them in my .gitignore. Of course I would like to not include those in the repo and just have them installed while deploying, just like with nuget packages. I tried to follow this guide http://gregtrowbridge.com/deploying-a-bower-dependent-node-app-on-windows-azure/ but still nothing seems to happen. So any help is welcome :)

Best regards

Zain Rizvi
  • 23,586
  • 22
  • 91
  • 133
Rasmus Christensen
  • 8,321
  • 12
  • 51
  • 78

3 Answers3

15

All of Azure Websites workers have bower pre-installed and should be on your path.

All you need to do is add a custom deployment script that would do bower install Here is a sample repo for an ASP.NET MVC site that uses bower

Basically make sure bower.json is there and referenced in your csproj

    <Content Include="bower.json" />

Then download your custom deployment script. if you go to https://<yourSiteName>.scm.azurewebsites.net then click on Tools -> Download custom deployment script or just download it from D:\home\deployment\tools then check it in the root of your repo like here basically there will be 2 files deploy.cmd and .deployment

this is the deployment logic, add a step to restore bower in it like here after the last step there

:: 4. Bower Install
if EXIST "%DEPLOYMENT_TARGET%\bower.json" (
    pushd "%DEPLOYMENT_TARGET%"
    call :ExecuteCmd bower install
    IF !ERRORLEVEL! NEQ 0 goto error
    popd
)
ahmelsayed
  • 7,125
  • 3
  • 28
  • 40
  • Will have to verify this again as i already tried this. Maybe I forgot to exclude some of the bower packages in .gitignore – Rasmus Christensen Feb 19 '15 at 07:26
  • try to deploy the repo I linked to and see if that works for restoring the correct bower components in the correct locations. You can browse the content of your site easily if you navigate to `https://.scm.azurewebsites.net/DebugConsole` then see what's different in your repo I guess and why restoring isn't happening – ahmelsayed Feb 19 '15 at 17:20
  • 1
    Thanks for the comment. I had an error in an external lib, and after some log reading and scm investigation is worked. Thanks for the tip – Rasmus Christensen Mar 06 '15 at 21:42
  • 1
    This worked for me, however, I needed to update the `IF EXISTS` part of the script about where to find the bower.json file. I have multiple projects in my solution, so I ended up with something like this: `if EXIST "%DEPLOYMENT_SOURCE%\PROJECT_FOLDER\bower.json" ( pushd "%DEPLOYMENT_SOURCE%\PROJECT_FOLDER" call :ExecuteCmd bower install IF !ERRORLEVEL! NEQ 0 goto error popd` – PeteK68 Oct 20 '16 at 16:54
1

You can use the console feature of Azure web app to fire the commands. Even if the console has access to a restricted features, you can still install the bower components by using the command:

bower install

The console option is listed under the deployment section of the Web Apps. You can refer the below the screen for reference.

Screen 1

Prerequisites:

  1. Do not publish the bowerComponents folder to the Web app.
  2. Include the bower.json file including all the dependencies.

Hope it helps.

Surabh Shah
  • 83
  • 1
  • 5
0

One important addition to the above - you must push both the unchanged .deployment file and modified .cmd file to deployment root for Azure to subsequently copy/execute your .cmd amendments. Otherwise it will regenerate a default .cmd