Teamcity 从CI中删除owin url注册

Teamcity 从CI中删除owin url注册,teamcity,owin,Teamcity,Owin,我使用以下OWIN实现在CI上运行功能测试 protected const string Url = "http://localhost:8785"; private static IDisposable _app; Establish context = () => _app = WebApp.Start(Url, a => { a.Use(typeof(MockIdentityMiddleware)); new S

我使用以下OWIN实现在CI上运行功能测试

    protected const string Url = "http://localhost:8785";
    private static IDisposable _app;

    Establish context = () => _app = WebApp.Start(Url, a =>
    {
        a.Use(typeof(MockIdentityMiddleware));
        new Startup().Configuration(a);
    });

    Cleanup after = () => _app.Dispose();
但当它运行时,我会得到以下堆栈跟踪:

System.Net.HttpListenerException:未能侦听前缀 “”因为它与现有的 在机器上注册


我想以编程方式删除该端口的注册,这样我就不必再担心,但不知道如何使用Owin进行注册。

您不应该在测试中硬编码端口号,因为您永远无法确定该端口是否可用

有一个非常简单的代码,可以在给定的机器上找到下一个可用的TCP端口