dotnet publish-IIS 在错误的位置查找 web.config



我无法让dotnet publish-iis正常运行。

要发布我正在使用的项目:

dotnet publish ./src/RetailGuardian.Web/ -o ./code_drop/RetailGuardian.Web --runtime dnet452

并且我在project.json中设置了一个发布后脚本:

"scripts": {
    "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
}

初始发布工作正常,并按预期将代码放在code_drop目录中(这是我过去在 RC1 中部署的,它工作正常)。但是,发布 IIS 在尝试查找 web.config 时似乎不使用输出路径。这是它运行时的输出:

Configuring the following project for use with IIS: './code_drop/RetailGuardian.Web'
No web.config found. Creating './code_drop/RetailGuardian.Webweb.config'
Could not find a part of the path 'G:ProjectsretailguardiansrcRetailGuardian.Webcode_dropRetailGuardian.Webweb.config'.
System.IO.DirectoryNotFoundException: Could not find a part of the path 'G:ProjectsretailguardiansrcRetailGuardian.Webcode_dropRetailGuardian.Webweb.config'.
   at System.IO.Win32FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, FileStream parent)
   at System.IO.Win32FileSystem.Open(String fullPath, FileMode mode, FileAccess access, FileShare share, Int32
bufferSize, FileOptions options, FileStream parent)
   at System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options)
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.PublishIISCommand.Run()
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.<>c__DisplayClass0_0.<Main>b__0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.Main(String[] args)
publish: Published to ./code_drop/RetailGuardian.Web
Published 1/1 projects successfully

因此,它尝试使用G:ProjectsretailguardiansrcRetailGuardian.Webcode_dropRetailGuardian.Webweb.config源目录,而不是G:Projectsretailguardiancode_dropRetailGuardian.Webweb.config发布输出所在的位置。

(奇怪的是,它还报告发布成功,即使发布后失败)

这似乎是一个错误,其中dotnet命令解析相对路径,然后更改当前目录以调用尝试再次解析路径的工具,但现在它相对于不同的文件夹解析它,因此最终路径不同。感谢您报告此问题 - 我在 cli 存储库中打开了一个问题:https://github.com/dotnet/cli/issues/3528

可能的解决方法:

  • 发布时使用绝对路径作为输出路径
  • 从项目文件夹发布

我遇到了这个问题,并通过在project.json的include-> publishOptions中添加web.config来解决它:

  "publishOptions": {
    "include": [
       ...
      "web.config"
    ]
  }

我的观察是,当您的终端意外关闭时,就会发生这种情况,而您的服务器没有正确关闭。最简单的解决方案是启动应用程序并正确停止它,然后尝试执行发布命令。

执行以下命令序列:

dotnet start
ctrl + c
dotnet publish ..

最新更新