我有類似的問題。起初,我只是將整個web.config應用程序設置部分複製到測試項目的app.config中。然後我發現OwinHost.exe,它(正如其名稱所暗示的)只是在當前目錄中查找啓動類並運行它們。因爲,它實際上會使用正確的web.config。這是我使用的是現在的代碼,隨時用它代替TESTSERVER的:
var psi = new ProcessStartInfo
{
FileName = Path.Combine(solutionRootPath, @"packages\OwinHost.3.0.1\tools\\OwinHost.exe"),
WorkingDirectory = packageFolder,
RedirectStandardError = true,
RedirectStandardOutput = true,
CreateNoWindow = true,
UseShellExecute = false
};
var process = Process.Start(psi);
process.ErrorDataReceived += (sender, args) =>
{
Console.WriteLine(args.Data);
};
process.OutputDataReceived += (sender, args) =>
{
Console.WriteLine(args.Data);
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
凡solutionRootPath是目錄包含解決方案,以及packageFolder是文件夾包含Web項目的二進制文件(項目的輸出目錄)。