簡體   English   中英

啟動 IIS Express cmd 而不是 VS2022

[英]Starting IIS Express cmd rather than VS2022

ASP.Net Core 6 Web Api 通過 VS2022 在 IIS Express 下正常運行,並允許我加載 swagger 頁面 (http://localhost:8084/swagger/index.html):

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: YYYY-DD-MM 17:49:22
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
YYYY-DD-MM 17:49:22 ::1 GET /_framework/aspnetcore-browser-refresh.js - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 6
YYYY-DD-MM 17:49:22 ::1 GET /swagger/index.html - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 - 200 0 0 3664
YYYY-DD-MM 17:49:22 ::1 GET /_vs/browserLink - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 59
YYYY-DD-MM 17:49:22 ::1 GET /swagger/v1/swagger.json - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 200 0 0 149

從 cmdline 運行它時:

"C:\Program Files (x86)\IIS Express\iisexpress" /config:applicationhost.config /site:TheWebApi

Swagger 不加載返回 HTTP 500:

#Software: Microsoft Internet Information Services 10.0
#Version: 1.0
#Date: 2022-11-19 17:54:41
#Fields: date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken
2022-11-19 17:54:41 ::1 GET /swagger/index.html - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 - 500 0 574 8
2022-11-19 17:54:41 ::1 GET /favicon.ico - 8084 - ::1 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/107.0.0.0+Safari/537.36 http://localhost:8084/swagger/index.html 500 0 574 0

Lex Li 的博客How Visual Studio Launches IIS Express to Debug ASP.NET Core Apps對我獲得有關正在發生的事情的更多信息非常有幫助。 顯然,VS2022 正在施展魔法,讓事情在調試模式下運行。 就我而言,我正在嘗試獲取桌面應用程序來啟動 ASP.Net Core 6 應用程序,因此調試不是問題。 當我查看事件日志時,我發現可能是什么問題,但不知道解決方案:

Application 'C:\Users\sam\source\repos\WebApplication1\' failed to start. Exception message:
Executable was not found at 'C:\Users\sam\source\repos\WebApplication1\bin\Debug\net5.0\WebApplication1.exe'

問題是應用程序是.Net 6,不是.Net 5。它最初是.Net 5,但已經升級到.Net 6。這讓我想到了......

我只是創建了一個新的 .Net WebApi 項目 (WebApplication2) 來比較生成的 applicationhost.conf 與真實項目 (WebApplication1)。 WebApplication1 具有以下不在 WebApplicaiton2 中的部分:

<site name="WebApplication1" id="2">
<application path="/" applicationPool="WebApplication1 AppPool">
  <virtualDirectory path="/" physicalPath="C:\Users\sam\source\repos\WebApplication1" />
</application>
<bindings>
  <binding protocol="http" bindingInformation="*:8084:localhost" />
</bindings>
</site>

由於我不想考慮 Visual Studio 2022,因此 physicalPath="C:\Users\sam\source\repos\WebApplication1\bin\Debug.net6.0" 應該嗎?

在我的特殊情況下,有一個桌面應用程序正在管理所討論的 ASP.Net Core 6 Web API 應用程序的執行。 事實證明,可以將 ASP.Net Core 6 Web API 應用程序發布到單個 EXE 中,這稱為Self-contained deployment 這就是我需要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM