4

In Visual Studio 2015 you could easily set an MVC app to use full IIS by right clicking on the project & going to properties.

It's not clear how to do this in a vanilla .NET Core Web (MVC) project in Visual Studio 2017.

I can find nothing about this on Google - am I looking in the wrong place?

niico
  • 11,206
  • 23
  • 78
  • 161
  • 2
    .NET Core does not support IIS in 2017 RTM. You can either use IIS Express or Kestrel directly. .NET Core support for IIS is something we're looking into for a future update to 2017. – Andrew Hall - MSFT Mar 07 '17 at 20:32
  • @AndrewHall-MSFT Do you mean that if I build an ASP.Net CORE web site using VS2017 I won't be able to host it behind IIS like I was doing with VS2015 (via Publish...) ? That would basically mean that we can't release yet an ASP.Net CORE based on VS2017 for production asof today? Also, does it mean I shouldn't update my nuget like Microsoft.AspNetCore.Server.Kestrel package from 1.1.0 to 1.1.1 under VS2015 if I need to keep hosting behind IIS? Thanks. – Daboul Mar 08 '17 at 15:40
  • .NET Core absolutely supports IIS. What Andrew meant is that the Visual Studio tooling for ASP.NET Core does not yet support projects using IIS for development. For development with Visual Studio your main options are IIS Express or Kestrel. – Sayed Ibrahim Hashimi Mar 10 '17 at 02:18
  • @SayedIbrahimHashimi was correct, my comment was in the context of using Visual Studio 2017 directly with IIS from a project to Debug/Run. As called out below, .NET Core works with IIS outside the context of Visual Studio – Andrew Hall - MSFT Mar 13 '17 at 18:37

1 Answers1

4

You can host it behind iis.

There are basicly four things you have to do besides having iis installed offcourse:

  1. Install the .NET Core Windows Server Hosting bundle. It can be found here https://go.microsoft.com/fwlink/?linkid=837808

  2. Include a dependency on the Microsoft.AspNetCore.Server.IISIntegration package in the application dependencies. Incorporate IIS Integration middleware into the application by adding the .UseIISIntegration() extension method to WebHostBuilder().

  3. Open cmd and run dotnet publish in your project

  4. host published application on iis. It is important that in application pool the .NET CLR version is set to 'No Managed Code'.

There is a more detailed article on how to publish your application to iis.

https://learn.microsoft.com/en-us/aspnet/core/publishing/iis

I didn't find a way to do it directly from visual studio 2017.

Update: you could use FlubuCore tool (C# fluent builder) to do step 3 and 4 for you automatically. You'd have to write flubu script that would look something like this(example is only for step 4):

protected override void ConfigureTargets(ITaskContext session)
{
    session.CreateTarget("iis.install").Do(IisInstall);
}

private static void IisInstall(ITaskContext context)
{
    context.Tasks().IisTasks()
        .CreateAppPoolTask("SomeAppPoolName")
        .ManagedRuntimeVersion("No Managed Code")
        .Mode(CreateApplicationPoolMode.DoNothingIfExists)
        .Execute(context);

    context.Tasks().IisTasks()
        .CreateWebsiteTask()
        .WebsiteName("SomeWebSiteName")
        .BindingProtocol("Http")
        .Port(2000)
        .PhysicalPath("SomePhysicalPath")
        .ApplicationPoolName("SomeAppPoolName")
        .WebsiteMode(CreateWebApplicationMode.DoNothingIfExists)
        .Execute(context);
}

And then to integrate it with visual studio 2017 run this script with flubu dotnet cli tool in prebuild or postbuild event with command 'dotnet flubu iis.install'. I Would rather run the tool from command line explicitly.

You can find more information about flubu and how to get started here: Choice for build tool: MSBuild, NANT or something else?

Community
  • 1
  • 1
Stan88
  • 252
  • 3
  • 12