3

I'm looking for a script (for example PowerShell) to deploy an ASP.NET 5 / MVC 6 application to Azure website. Ideally it would be a single script that builds the project and deploys it to Azure.

I would also like to run Entity Framework 7 migrations and do some custom JavaScript minification/bundling in the script.

I would really appreciate if any of you have ideas on how this can be accomplished, thanks!

bot
  • 4,841
  • 3
  • 42
  • 67
Samuli Haverinen
  • 415
  • 5
  • 10

2 Answers2

2

Let's separate topics first.

For deploying a Web app to Azure, why not use Continuous Integration? If you link your Web App with your repository, you can pick a branch and everytime you push to that branch, it gets deployed on Azure.

You can go a step further and configure Deployment Slots (a staging one in particular) and configure Auto-Swap to reduce Cold starts.

For Javascript minification, you can just use Gulp/Grunt with tasks that either, run on your development environment (and you commit to your repository the minified output) or you can run the tasks as a "postrestore" action defined in your project.json file. A simple:

{
  "scripts": {
    "postrestore": ["npm install", "bower install","gulp default"]
  }
}

Will do the trick by pulling your defined bower packages and then running the default gulp task.

Your default gulp task can be something like:

var gulp = require('gulp');  
var mainBowerFiles = require('main-bower-files');
var bower = require('gulp-bower');  
var uglify = require('gulp-uglify');
var ignore = require('gulp-ignore');
var del = require('del');

var project = require('./project.json');  
var lib = project.webroot + '/dist'; 

gulp.task('clean',function(done){
    del(lib, done);
});

gulp.task('bower:install', ['clean'], function () {  
    return bower();
});

gulp.task('default', ['bower:install'], function () {  
    return gulp.src(mainBowerFiles())
        .pipe(ignore.exclude([ "**/*.css","**/*.less" ]))
      .pipe(uglify())
      .pipe(gulp.dest(lib+'/js'));
});
Matias Quaranta
  • 13,907
  • 1
  • 22
  • 47
  • Thanks. This looks like a nice way to handle the deployment! How would you run EF7 migrations on deployment? If I understand correctly this can be done in Startup.cs but does it work if I rollback to a previous version from the Azure portal? – Samuli Haverinen Dec 19 '15 at 03:34
  • The continuous deployment fails with an error for me. [Separate question here](http://stackoverflow.com/questions/34367202/azure-web-app-mvc-6-continuous-deployment-fails). – Samuli Haverinen Dec 19 '15 at 04:16
0

You can use both PowerShell and Visual Studio Team Services to automate the deployment of your web app in Azure.

For example, it's possible to make a workflow that executes some PowerShell script that executes DNU restore, code migrations and then publish the web app as soon as a commit is done on your source code repository.

I think the following article will help you: https://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5

Hope this helps,

Julien

Julien Corioland
  • 1,115
  • 6
  • 9