Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run ASP.NET MVC6 on IIS without publishing application

Tags:

asp.net-core

I am trying to find a way to run MVC6 application on IIS but without actually doing the publish. I am not sure if that is possible, and if not will it be possible in the future?

I would like to have similar behavior like on previous versions where I could easily debug my code and make changes while the application is running under IIS.

like image 335
zoranpro Avatar asked Jul 02 '15 20:07

zoranpro


2 Answers

From your original question (emphasis added):

I am trying to find a way to run MVC6 application on IIS but without actually doing the publish.

From your comment to tugberk (emphasis added):

Right now every time when I make a change I need to call that dnu publish command in order to see my changes on IIS. I would like to see them only by doing rebuild.

Answer and reasons

You'll need to publish. There are at least two reasons:

  • IIS needs build output and
  • IIS needs a web.config file.

IIS might need a few other things too, about which I'm not aware. So, you'll need to publish. This isn't a big deal: after the onetime setup, publish doesn't take much longer than rebuild does.

Why do you need to publish?

In Visual Studio 2015, if you build an ASP.NET 5 web app, there will be no build output under your solution's directory, and IIS needs build output. By default Roslyn only runs code analysis without emitting build output.

You can change that default, so that Roslyn does emit build output, but that won't produce the web.config file that IIS needs. By going to View > Project Properties > Build and checking "Produce outputs on build", Roslyn will emit output to the artifacts directory. E.g:

artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.nupkg
artifacts/bin/MyWebApp/Debug/MyWebApp.1.0.0.symbols.nupkg
artifacts/bin/MyWebApp/Debug/app/project.json
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnx451/MyWebApp.xml
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.dll
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.pdb
artifacts/bin/MyWebApp/Debug/dnxcore50/MyWebApp.xml

If you point IIS at the artifacts directory, you'll now have the problem of having neither a wwwroot nor a web.config.

So, you need to publish (or work out some other convoluted solution) for IIS to work with ASP.NET 5. There is a onetime setup if you want to publish from Visual Studio to a local IIS website. After the onetime setup, you can make changes to your code and publish in two clicks. Here's the onetime setup:

  • Right click the project.
  • Choose Publish.
  • Select File System and add a profile name (e.g. inetpub).
  • Change the target location to C:\inetpub\MyWebApp
  • In Settings, select appropriate settings. E.g.
    • Configuration: Debug
    • Target DNX Version: dnx-clr-win-x64.1.0.0-beta4
  • Click Publish.

Once publish completes, point IIS at C:\inetpub\MyWebApp\wwwroot and you will be able to browse to the web site. Further to the point, you can now change your code, publish in two clicks, and refresh your IIS site to see the changes.

Some gotchas

  • If you do choose to publish to inetpub, be sure to run Visual Studio as administrator, lest you receive an insufficient permissions error.

  • If you accept the default publish location (instead of using inetpub as shown above) watch out for path too long errors (i.e. > 260 characters.)

Final thoughts

Why not use Visual Studio and Debug > Start without debugging during development. With Roslyn and Visual Studio 2015, you can make changes to the code and see those changes by refreshing the web browser. No rebuild is necessary. It's a much nicer workflow.

like image 199
Shaun Luttin Avatar answered Dec 30 '22 05:12

Shaun Luttin


It's possible. Under the root of your project (project.json directory), run the following command:

dnu publish --runtime active --out bin/artifacts

Once the publish is done, you have some stuff under bin/artifacts folder. Point IIS application pool to bin/artifacts/wwwroot folder we have just created and it should work. Keep in mind that you at least need .NET 4.5.1.

like image 38
tugberk Avatar answered Dec 30 '22 04:12

tugberk