Visual Studio 無法啟動 IIS Express Server 問題

Visual Studio Unable to launch the IIS Express Web server
最近時常在兩台電腦間交互辦公,一台在家裡一台是筆電,檔案用 OneDrive 自動同步,所以我每次打開電腦就可以立刻接上另外一台電腦的進度立刻開始辦公
最近開始遇到一個奇怪的問題就是偶爾 Visual Studio 無法啟動 IIS Express Server 開始進行偵錯,都會出現以下錯誤畫面

首先最快也最簡單的方式就是先把 Visual Studio 重開看看
不型的話則先透過 netstat 來判斷是否網站要使用的 port 已被占用

netstat
透過 netstat 指令查詢後,可以發現指定的 port 並沒有被占用,所以不會是 port 的問題
# 也可以透過以下指令只看特定 port 的清單
netstat -ao | findstr <port_number_to_search_for>
再來的話,也是我這情況的原因就是 applicationhost.config 被鎖住了
先到 {ProjectSource}\.vs\config 資料夾中,將 applicationhost.config 此檔案刪除掉
最後再打開 Visual Studio 開始執行,就可以正常工作了
備註:若刪除此檔案還不行,可以嘗試刪除
Users/<username>/Documents/IISExpress/config下的applicationhost.config若是專案放置於 One Drive 目錄下,可以先試試將 One Drive 關閉,然後砍掉
applicationhost.config在開啟 Visual Studio 方式,有時會是 One Drive 導致的問題
參考
[How to solve IIS issue in visual studio? This site uses cookies to deliver our services and to show you relevant ads and job listings. By using our site, you…stackoverflow.com](https://stackoverflow.com/questions/29116292/how-to-solve-iis-issue-in-visual-studio "https://stackoverflow.com/questions/29116292/how-to-solve-iis-issue-in-visual-studio")

![[IT 鐵人賽] ASP.NET Core 與 Log 紀錄和追蹤的愛恨交織 - Day 05 - Elmah - 02](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1776070454149%2Fa0702417-5357-4217-a572-7ba53ea36735.png&w=3840&q=75)
![[IT 鐵人賽] Azure Data Service - Day 04 - Cognitive Service - 辨識 - Video Indexer](/_next/image?url=https%3A%2F%2Fcdn.hashnode.com%2Fres%2Fhashnode%2Fimage%2Fupload%2Fv1776070473207%2F6423fd4a-4041-4bb2-b918-4cfe3f9aea5e.png&w=3840&q=75)