我有类似的问题。起初,我只是将整个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项目的二进制文件(项目的输出目录)。