2017-05-02

Visual Studio Solution File and IIS Express Settings

使用 Visual Studio 開發 Web application 時,solution file (*.sln) 是主要的設定檔。Visual Studio 這邊一個設計不好的地方在於,sln 檔裡頭會記錄 IIS Express 使用的 port number。

傳統上一般開發好的 Web application 會透過手動複製或 web deploy 的方式佈署到執行環境上,但在開發測試時,實際佈署的執行環境是 Visual Studio 自帶的 IIS Express;如同一般的 IIS 一樣,IIS Express 也需要一個 port number 來作為 HTTP entry point,例如:http://localhost:54321。

應用程式跟 port number 的對應關係會記錄在 %USERPROFILE%\Documents\IISExpress\config\applicationhost.config 中,主要記錄 site name, physical path, and port number;一般當多人協同開發時,各自的 physical path 皆不相同,不會將 applicationhost.config commit 上 version control,而是交給開發人員各自管理。

麻煩的是帶有 port number 作為開發專案的重要設定必須 commit 到 version control,加上該設定又帶了 port number,間接限定了所有共同開發的人員對於相同的 solution 都必須手動維護 IIS Express applicationhost.config 設定,使用同一個 port number。

ps. Windows 預帶一些指向特定目錄的環境變數,這些變數在設定應用程式時經常用到,但卻在 系統內容/環境變數 中找不到,它們的正式名稱是 Constant Special item ID List (CSIDL),這邊的 %USERPROFILE% 就是常見的一個。

see also: CSIDL