36

How can I setup a .Net Core 1.0 project to use Local IIS instead of IIS Express when debugging?

I have tried modifying launchSettings.json file in various ways. For example, replacing all occurrences of IIS Express with Local IIS and updating the applicationUrl and launchUrl to use my custom localhost http://sample.local (I have updated the host file and configured IIS manager already) but not happy.

Default settings of Properties/launchSettings.json file:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:38601/",
      "sslPort": 0
    }
  },
  "profiles": {
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "SampleApp": {
      "commandName": "Project",
      "launchBrowser": true,
      "launchUrl": "http://localhost:5000",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}
Oluwafemi
  • 14,243
  • 11
  • 43
  • 59

1 Answers1

44

You currently cannot directly use IIS to host an ASP.NET Core application while developing, as the development folder does not provide all of the necessary files IIS needs to host. This makes running an ASP.NET Core in a development environment a bit of a pain.

As pointed out in this article by Rick Strahl, there aren't many reasons to try and do this. IIS does very little when running ASP.NET Core apps - in fact your application no longer runs directly in the IIS process, instead it runs in a completely separate console application hosting the Kestrel web server. Therefore you really are running in essentially the same environment when you self host your console application.

If you do need to publish your app, you can do so to a local folder, using either the dotnet command line, or using the Visual Studio tools.

For example, if you want to publish to the C:\output folder, you can use the following command:

dotnet publish
  --framework netcoreapp1.0 
  --output "c:\temp\AlbumViewerWeb" 
  --configuration Release

You can then point your IIS Site at the output folder. Ensure that you set the application pool CLR version to No Managed Code and that the AspNetCoreModule is available.

For more details, see https://docs.asp.net/en/latest/publishing/iis.html

Sock
  • 5,323
  • 1
  • 21
  • 32
  • 14
    I do not get Rick Strahl's argument. If you are developing a .NET back-end with a JS front-end, for instance, you need to have the back-end running the whole time. I now have to either publish the back-end each time I make a change, or open my back-end project in visual studio and leave debug running. Whereas previously, I would just build as necessary and host via IIS. It's one extra step now, not great. – Andy-Delosdos Aug 06 '16 at 11:22
  • 4
    That's actually the argument he is making for _not_ using IIS when you are developing. Instead of doing that in development, just run directly on Kestrel using `dotnet run` before you start your JS front end work. That way you don't need the solution open, don't need to publish and don't need to use IIS at all. – Sock Aug 06 '16 at 16:47
  • 9
    In pre-.NET core versions of .NET your app can be hosted by IIS, you don't need to open Visual Studio unless you specifically need to make changes. After making changes, just hit build and you're done. With Kestrel, not only do need to build, you also need to either publish OR use `dotnet run` before you start your JS front end dev - this is an extra step. I get his argument, I just don't agree it's easier or better – Andy-Delosdos Aug 06 '16 at 21:42
  • 5
    Yep, I often host in IIS locally, though my reason for it are the behavioural differences between IIS and IIS express, which no longer exists in Core. I accept using `dotnet run` is an extra step, but if you want to get closer to the 'edit and you're done' approach, take a look at using `dotnet watch run`. That even removes the need to explicitly build. Just edit the files (in e.g. notepad) and refresh the browser. Have a look at this link for details: https://jonhilton.net/2016/08/04/compile-your-changes-on-the-fly-with-net-core/ – Sock Aug 08 '16 at 06:33
  • Yes, as i maintain quite a lot of websites, it's convenient to have the dev sites setup in IIS, especially if i only need to make tweaks to the front-ends . That `dotnet watch run` looks quite handy, thank you :) – Andy-Delosdos Aug 08 '16 at 10:48
  • 7
    I find this unacceptable that you have to publish site in order use Full IIS. Esp. there is no real powershell API available to setup IIS express... Fustrating really... thumbs down Microsoft... – activebiz Jan 31 '17 at 08:28
  • I have the same issue in whole another context, I'm debugging Xamarin Android app with .Net Core API back-end. What should I do? – Emad Mar 17 '17 at 21:51
  • @DonnyV. Just double checked and `dotnet watch` still looks to work to me? It does seem to give occasional errors, but otherwise works as expected as far as I can tell – Sock Jun 11 '17 at 18:03