Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change hostingModel="OutOfProcess" while publishing to IISServer?

I set HostingModel to "Out Of Process" in VS Debug window. But when publish the project to my DEV server. web.config file showing always hostingModel="inprocess". If I remove this attribute I can run the application.

Is there any process while publishing we change hostingModel to OutOfProcess. I am using ASP.Net Core 3.1 version for WebAPI

enter image description here

like image 668
James123 Avatar asked Mar 18 '20 20:03

James123


4 Answers

For Visual Studio 2019, changing the project file does not solve the problem.

The following line:

<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

Should be added inside in the publish profile "YourProfileName".pubxml file lying in the Properties/PublishProfiles/ project directory.

like image 148
nefen Avatar answered Oct 22 '22 10:10

nefen


You need to understand the hierarchy of .Net core in order to understand exactly what you need to know.

Where .NetCore read this configuration from:
First:
web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <!--
    Configure your application settings in appsettings.json. Learn more at https://go.microsoft.com/fwlink/?LinkId=786380
  -->
  <system.webServer>
    <modules>
      <remove name="WebDAVModule" />
    </modules>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess"></aspNetCore>
  </system.webServer>
</configuration>

The value hostingModel="InProcess" will override all other configuration existing in your project.

Second: publish profile

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <DeleteExistingFiles>True</DeleteExistingFiles>
    <ExcludeApp_Data>False</ExcludeApp_Data>
    <LaunchSiteAfterPublish>True</LaunchSiteAfterPublish>
    <LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
    <LastUsedPlatform>Any CPU</LastUsedPlatform>
    <PublishProvider>FileSystem</PublishProvider>
    <PublishUrl>bin\Release</PublishUrl>
    <WebPublishMethod>FileSystem</WebPublishMethod>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <EnvironmentName>staging</EnvironmentName>
  </PropertyGroup>
</Project>

The relevant node is AspNetCoreHostingModel

Third: .csproj

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
    <TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
    <TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
    <IsPackable>false</IsPackable>

Any value you will have in .csproj or publish profile will get overridden by the webconfig.

like image 44
Offir Avatar answered Oct 22 '22 11:10

Offir


Change the properties in VS Debug window, the project's launchsettings.json file is updated synchronously, and launchsettings.json is for VS running the project. To configure an app for out-of-process hosting, set the value of the <AspNetCoreHostingModel> property to OutOfProcess in the project file (.csproj):

<PropertyGroup>
  <TargetFramework>netcoreapp3.1</TargetFramework>
  <AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>
</PropertyGroup>

Reference: https://docs.microsoft.com/en-us/aspnet/core/host-and-deploy/aspnet-core-module?view=aspnetcore-3.1

like image 33
Xueli Chen Avatar answered Oct 22 '22 10:10

Xueli Chen


You can change your project file. add

<AspNetCoreHostingModel>OutOfProcess</AspNetCoreHostingModel>

inside PropertyGroup

like image 20
Haokai Avatar answered Oct 22 '22 12:10

Haokai