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!

2 Answers 2

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'));
});
Sign up to request clarification or add additional context in comments.

2 Comments

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?
The continuous deployment fails with an error for me. Separate question here.
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.