最近遇到兩次,特筆記備忘。
在Windows 8.1使用Visual Studio 2015偵錯ASP.NET網站,修改web.config後存檔,出現被其他程序佔用無法存取錯誤。
The process cannot access the file '…web.config' because it is being used by another process.
無法存取檔案 '…web.cofig',因為其他處理序正在使用此檔。

優先猜想web.config是被IIS Express鎖定,嘗試從工具列停止站台,問題依舊。

換個方法,在檔案總管將檔案更名想確認是否web.config真被鎖定無法更動,意外得到更明確的錯誤訊息,Windows直接供出嫌犯是Microsoft.VisualStudio.Web.Host.exe。

利用工具管理員將Microsoft.VisualStudio.Web.Host.exe排除,問題排除。

事後在Stackoverflow查到類似討論(有VS2015+Windows 10案例)但無明確結論,以強制中止Microsoft.VisualStudio.Web.Host.exe為暫時解法。
另外本次學到一招:遇到檔案被鎖住,可先改從檔案總管更名,有可能Windows會直接回報鎖定來源,省去動用ProcessExplorer、Unlocker… 等工具的手續。