此功能需要 Microsoft.Testing.Extensions.HotReload NuGet 套件。
小提示
當使用 Microsoft.Testing.Platform.MSBuild (MSTest、NUnit 和 xUnit 執行程式可傳遞包含)時,安裝其 NuGet 套件時,此擴充功能會自動註冊——無需修改程式碼。 本文所規定的手動註冊僅在你透過設定 <GenerateTestingPlatformEntryPoint>false</GenerateTestingPlatformEntryPoint>關閉自動產生的入口點時才需要。
手動註冊
var builder = await TestApplication.CreateBuilderAsync(args);
builder.TestHost.AddHotReloadProvider();
即時重新載入
Hot reload 讓你在應用程式執行時修改管理的原始碼,無需手動暫停或觸發斷點。 只要在應用程式運行時進行支援的變更,然後在Visual Studio中選擇套用程式碼變更按鈕即可套用你的編輯。
備註
目前版本僅限於支援「主機模式」下的 hot reload。 目前 Visual Studio 的測試總管中不支援 hot reload 或 Visual Studio Code。
備註
此套件附帶 Microsoft.Testing.Platform Tools 的限制性授權。 完整授權可在 https://www.nuget.org/packages/Microsoft.Testing.Extensions.HotReload/1.0.0/License取得。
你可以把 TESTINGPLATFORM_HOTRELOAD_ENABLED 環境變數設成 "1",輕鬆啟用 hot reload 支援。
針對 SDK 樣式專案,您可以在 "TESTINGPLATFORM_HOTRELOAD_ENABLED": "1" 檔案的 [environmentVariables] 區段中新增 launchSettings.json。 下列代碼段顯示範例檔案:
{
"profiles": {
"Contoso.MyTests": {
"commandName": "Project",
"environmentVariables": {
"TESTINGPLATFORM_HOTRELOAD_ENABLED": "1"
}
}
}
}