Visual Studio發佈時移除指定檔案
網頁開發時都會有一個設定檔,Web Config、AppSettings
因開發環境與正式環境,會有差異,故在發佈的當下不希望去修改到這些資料項目
解決辦法有許多種,不外乎發行後移除檔案,再部屬環境,或是依照環境變數採用設定檔資料
以下提供一種比較簡易的方式
Visual Studio
VS上執行過發佈,會出現一個PublishProfiles

當我們點擊底下的資料FolderProfile.pubxml會看到發行的設定資訊

此時我們可以在上面添加一些指令例如
<ItemGroup>
<Content Remove="appsettings.Development.json" />
<Content Remove="appsettings.json" />
<Content Remove="NLog.config" />
</ItemGroup>

當我們執行VS發行功能時,可以看到指定的資料夾中,已不存在移除的檔案
這樣就可以完成簡易的發行檔案動作