dotnet run 挂起/卡住

问题描述 投票:0回答:1

razor webapp 无法再在我的计算机上启动。

构建命令

dotnet build
按预期工作,但
dotnet run
在第一次警告后卡住了。

C:\dev\mywebapp>dotnet run
Building...
C:\dev\mywebapp\Pages\Admin\Orders\TraderOrderList.cshtml.cs(101,17): 
     warning CS0219: The variable 'orderId' is assigned but its value is 
                     never used [C:\dev\mywebapp\MyWebApp.csproj]

C:\dev\mywebapp\Pages\Index.cshtml.cs(23,24): 
     warning CS0414: The field 'IndexModel._currentAd' is assigned but its value is
                     never used [C:\dev\mywebapp\MyWebApp.csproj]

--- after here it is stuck no more output and i stopped it after about 3 minutes

我尝试了什么?

  • 我创建了一个新项目
    c:\dev\webtemp>dotnet new webapp -o HelloWebApp
  • 并用
    c:\dev\webtemp\HelloWebApp>dotnet run
    运行它。所以这按预期工作。

我在stackoverflow上搜索了其他问题,但没有遇到同样的问题。

问题

  • 如何缩小问题范围?
  • dotnet run 命令的日志文件在哪里?

dotnet --信息

为简洁起见,以下某些路径已被替换

所使用的名字 路径
<path-to-AspNetCore.App>
C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App
<path-shared-NETCore>
C:\Program Files\dotnet\shared\Microsoft.NETCore.App
<path-shared-WindowsDesktop>
C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App

运行

dotnet --info
返回

c:\dev\webtemp\HelloWebApp>dotnet --info
.NET SDK:   Version:   7.0.100 Commit:    e12b7af219

Runtime Environment:
 OS Name:     Windows  OS Version:  10.0.19042
 OS Platform: Windows RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.100\

Host: Version:  7.0.0   Architecture: x64  Commit:       d099f075e4

.NET SDKs installed:
  3.1.120 [C:\Program Files\dotnet\sdk]    3.1.426 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.113 [C:\Program Files\dotnet\sdk]
  7.0.100 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 3.1.20 [<path-to-AspNetCore.App>]
  Microsoft.AspNetCore.App 3.1.32 [<path-to-AspNetCore.App>]
  Microsoft.AspNetCore.App 5.0.17 [<path-to-AspNetCore.App>]
  Microsoft.AspNetCore.App 6.0.13 [<path-to-AspNetCore.App>]
  Microsoft.AspNetCore.App 7.0.0 [<path-to-AspNetCore.App>]
  Microsoft.NETCore.App 3.1.20 [<path-shared-NETCore>]
  Microsoft.NETCore.App 3.1.32 [<path-shared-NETCore>]
  Microsoft.NETCore.App 5.0.17 [<path-shared-NETCore>]
  Microsoft.NETCore.App 6.0.13 [<path-shared-NETCore>]
  Microsoft.NETCore.App 7.0.0 [<path-shared-NETCore>]
  Microsoft.WindowsDesktop.App 3.1.20 [<path-shared-WindowsDesktop>]
  Microsoft.WindowsDesktop.App 3.1.32 [<path-shared-WindowsDesktop>]
  Microsoft.WindowsDesktop.App 5.0.17 [<path-shared-WindowsDesktop>]
  Microsoft.WindowsDesktop.App 6.0.13 [<path-shared-WindowsDesktop>]
  Microsoft.WindowsDesktop.App 7.0.0 [<path-shared-WindowsDesktop>]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:   Not set
global.json file:        Not found

更新 - 使用另一个分支返回 404

我确实更改了分支,并且

dotnet run
到达了本地主机启动的部分。

info: Microsoft.Hosting.Lifetime[14]
      Now listening on: https://localhost:7178 info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://localhost:5057 info: Microsoft.Hosting.Lifetime[0]
      Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0]
      Hosting environment: Development info: Microsoft.Hosting.Lifetime[0]
      Content root path: C:\dev\mywebapp\

但它返回http 404

404 未找到

服务器找不到所请求的资源。 ...

服务器也可以将此响应而不是 403 Forbidden 发送至 对未经授权的客户端隐藏资源的存在。

我尝试了几个不同的网址,但每个剃刀页面都失败了(404)。只有wwwroot下的静态html页面有效(200)

路径 网址 结果
C:\...\wwwroot\index.htm
https://localhost:7178/index.htm
200
C:\...\Pages\info.cshtml
https://localhost:7178/privacy
404
如上所述
https://localhost:7178/privacy.cshtml
404
如上所述
https://localhost:7178/Pages/privacy/
404
如上所述
https://localhost:7178/Pages/privacy.cshtml
404

这里可以看到devtools的截图

c# .net kestrel-http-server .net-7.0
1个回答
0
投票

前几天我遇到了类似的问题。

就我而言,我使用 NLog 进行日志记录。我已经输入了所有必要的代码和配置,但忘记在我的项目中创建

nlog.config
文件。缺少
nlog.config
文件导致应用程序挂起。

© www.soinside.com 2019 - 2024. All rights reserved.