【问题标题】:.NET core 3 API, develop on Mac with Visual Studio Code: how deploy and configure on IIS?.NET core 3 API,在 Mac 上使用 Visual Studio Code 开发:如何在 IIS 上部署和配置?
【发布时间】:2020-04-07 16:21:09
【问题描述】:

我在 Mac 上使用 Visual Studio Code 开发了一个带有 .Net Core 3 的 Web API,没有问题。 我用命令发布: dotnet publish -c release

但我无法在 IIS 上部署: 发布命令不会生成任何“web.config”文件,所以我使用我在网上找到的这个配置(可能是针对 Core 2.0 的?):

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet"
                  arguments=".\thenameofmydll.dll"
                  stdoutLogEnabled="false"
                  stdoutLogFile=".\logs\stdout"
                  hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

我的“program.cs”:

public class Program
    {
        public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();

        }

         public static IHostBuilder CreateHostBuilder(string[] args) =>
           Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                }); 
    }

我的问题:

  • “program.cs”是否可以与 IIS 一起使用?

  • “web.config”是否正确?

我在网上找到了几个示例,但所有这些都是部分或不完整的......如果我要求以前问过的东西,很抱歉,但我找不到 .Net Core 3 的完整示例

谢谢!

【问题讨论】:

  • 无法重现您所说的内容。 web.config 即使在 macOS 上也会生成。

标签: c# macos iis .net-core webapi


【解决方案1】:

根据asp.net core document

如果省略 -r 参数,则会为您当前的平台创建一个可执行文件。

我建议您可以尝试在命令中设置运行时版本,然后重试。它将添加 web.config 文件。

dotnet publish
 -c Release
 -f netcoreapp3.1 
-r win-x64 

此外,任何具有目标平台特定平台依赖项的 NuGet 包都将复制到发布文件夹。

【讨论】:

    【解决方案2】:

    Microsoft documentations 可用于 IIS 中的 .Net CORE 3.x 应用程序部署。 简而言之,首先您需要在 IIS 服务器中为 .Net core 3.x 安装 Hosting bundle。 然后,您可以将应用程序发布为自包含应用程序或依赖于框架的应用程序。您可以在设置发布设置时选择此选项。

    你的 web.config 应该是这样的

    <configuration>
       <location path="." inheritInChildApplications="false">
         <system.webServer>
           <handlers>
             <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" 
             resourceType="Unspecified" />
           </handlers>
           <aspNetCore processPath=".\<app name>.exe" 
           stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" 
           />
        </system.webServer>
      </location>
    </configuration>
    

    【讨论】:

      猜你喜欢
      • 2019-10-17
      • 2019-01-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-15
      • 2020-07-16
      相关资源
      最近更新 更多