Set up Visual Studio 2017 for .Net Core Application Development


The Default Profile setting in LibPrograms/Properties/LaunchSettings.json

{

  "iisSettings": {

    "windowsAuthentication": true,

    "anonymousAuthentication": true,

    "iis": {

      "applicationUrl": "http://localhost:8000",

      "sslPort": 0

    },

    "iisExpress": {

      "applicationUrl": "http://localhost:49497/",

      "sslPort": 0

    }

  },

  "profiles": {

    "IIS": {

      "commandName": "IIS",

      "launchBrowser": true,

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      }

    },

    "IISExpress": {

      "commandName": "IIS",

      "launchBrowser": true,

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      },

      "use64Bit": false

    },

    "LibPrograms": {

      "commandName": "Project",

      "launchBrowser": true,

      "environmentVariables": {

        "ASPNETCORE_ENVIRONMENT": "Development"

      },

      "applicationUrl": "http://localhost:49498/"

    }

  }

}

  • Enable Development time IIS support for .Net Core Application

This setup is for running with IIS  profile. Without this setup, you'll see error "AspNetCore module is not installed ..." when you try to click IIS profile to run.

Firstly download  and run Visual Studio Installer:


Then check Development time IIS support from ASP.NET and web development.
For details please refer to .NET Web Development and Tools Blog.

  • Self-contained deployment with Visual Studio

Edit LibPrograms.csproj file and add the following highlight lines and the publish the project:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64</RuntimeIdentifiers>
    <NoWarn>$(NoWarn);NU1605</NoWarn>
  </PropertyGroup>
...

</Project>

Please note:    <NoWarn>$(NoWarn);NU1605</NoWarn> is for working around the following publishing error: .NET Core 2.0.0 - downgrade warnings have become errors when running package restore #5594.

Error NU1605 Detected package downgrade: System.Security.Principal from 4.3.0 to 4.0.1. Reference the package directly from the project to select a different version. 
 LibPrograms -> Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.0 -> Microsoft.Build.Runtime 15.3.409 -> Microsoft.Build 15.3.409 -> System.IO.Pipes 4.0.0 -> System.Net.Sockets 4.1.0 -> runtime.win.System.Net.Sockets 4.3.0 -> System.Security.Principal.Windows 4.3.0 -> System.Security.Principal (>= 4.3.0) 
 LibPrograms -> Microsoft.VisualStudio.Web.CodeGeneration.Tools 2.0.0 -> Microsoft.Build.Runtime 15.3.409 -> Microsoft.Build 15.3.409 -> System.IO.Pipes 4.0.0 -> System.Security.Principal (>= 4.0.1) LibPrograms

For details of deployment please refer to Deploying .NET Core apps with Visual Studio,

Self-contained app can be run in the following ways:


  • C:\>LibPrograms.csproj.exe 
        Access URL by default: http://localhost:5000
  • C:\>C:\Program Files\dotnet\dotnet.exe  LibPrograms.csproj.dll 
        Access URL by default: http://localhost:5000

  • Deployed to IIS, for example deployed to http://localhost:8000 at C:\inetpub\wwwroot\LibPrograms

When you trying to access http://localhost:8000, you most likely see the following error:

HTTP Error 502.5 - Process Failure

Common causes of this issue:

  • The application process failed to start
  • The application process started but then stopped
  • The application process started but failed to listen on the configured port

Troubleshooting steps:

  • Check the system event log for error messages
  • Enable logging the application process' stdout messages
  • Attach a debugger to the application process and inspect

For more information visit: https://go.microsoft.com/fwlink/?LinkID=808681 



Please edit C:\inetpub\wwwroot\LibPrograms\web.config and remove the -argFile IISExeLauncherArgs.txt. Now it should work.

<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath=".\LibPrograms.exe" arguments="-argFile IISExeLauncherArgs.txt" forwardWindowsAuthToken="true" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

Credit to danielyewright at ASP.Net Core app - HTTP Error 502.5 - Process Failure

  • Framework-dependent deployment with Visual Studio

The working LibPrograms.csproj file is as follows:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
  </PropertyGroup>
...
</Project>

During deployment I kept receiving this error:

Severity Code Description Project File Line Suppression State
Error Assets file 'C:\dev\wan\LibPrograms\LibPrograms\obj\project.assets.json' doesn't have a target for '.NETCoreApp,Version=v2.0/win10-x64'. Ensure that restore has run and that you have included 'netcoreapp2.0' in the TargetFrameworks for your project. You may also need to include 'win10-x64' in your project's RuntimeIdentifiers. LibPrograms


In Publish / Settings / Databases / Check Use this connection string at runtime

What was weird is: after this success, the deployment always worked even though I unchecked Use this connection string at runtime. Caused by cache? Any update to publish settings may fix it. For example, delete and create the profile for publish.

If HTTP Error 502.5 - Process Failure error showed up again, please edit web.config and remove  -argFile IISExeLauncherArgs.txt as follows:

<configuration>
  <system.webServer>
    <handlers>
      <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
    </handlers>
    <aspNetCore processPath="dotnet" arguments=".\LibPrograms.dll -argFile IISExeLauncherArgs.txt" forwardWindowsAuthToken="true" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" />
  </system.webServer>
</configuration>

Please don't forget  Install the .NET Core Windows Server Hosting bundle.


Method 1: in Visual Studio , directly remove the high light content from the source web.config

    <aspNetCore processPath="bin\IISSupport\VSIISExeLauncher.exe" arguments="-argFile IISExeLauncherArgs.txt" forwardWindowsAuthToken="true" stdoutLogEnabled="false" >
</aspNetCore>


Method 2: Using PowerShell Script

BlueWater86 commented 21 days ago  

The same can be achieved by using a powershell script. Put the file in the root of your project and set it to 'Content', 'Copy Always'.
CleanDeployArgs.ps1:
param([string]$path)
(get-content "$($path)web.config") -replace ' -argFile IISExeLauncherArgs.txt', '' | out-file "$($path)web.config" -Encoding UTF8
Line at the bottom of your csproj file:
  <Target Name="CleanDeployArgs" AfterTargets="_TransformWebConfig">
    <Exec Command="powershell.exe –NonInteractive –ExecutionPolicy Unrestricted  –command &quot;&amp; { &amp;'$(PublishDir)CleanDeployArgs.ps1'  '$(PublishDir)'}&quot;" />
  </Target>






Comments

Post a Comment

Popular posts from this blog

Use GnuPG Tools or C# Code for PGP Encryption and Signature

Errors in Net Core Add-Migration

Confusing Concepts about SFTP: SSH2 vs OpenSSH