0

我用以下启动类创建了一个新的类库项目:

public class Startup
{
    public void Configure(IAppBuilder app)
    {
        app.Run(ctx =>
        {
            ctx.Response.StatusCode = 200;
            ctx.Response.ContentType = "text/plain";
            return ctx.Response.WriteAsync("Hello from Owin");
        });
    }
}

我安装了以下软件包:

<packages>
  <package id="Microsoft.Owin" version="2.1.0" targetFramework="net45" />
  <package id="Microsoft.Owin.Host.HttpListener" version="2.1.0" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
  <package id="OwinHost" version="2.1.0" targetFramework="net45" />
</packages>

当我尝试从中运行owinhost.exe时,/bin/debug出现以下错误:

Error:  System.EntryPointNotFoundException
  The following errors occurred while attempting to load the app.
 - No assembly found containing an OwinStartupAttribute.
 - No assembly found containing a Startup or [AssemblyName].Startup class.

我是否需要做任何其他事情才能让 OwinHost.exe 与类库项目一起工作(我在控制台应用程序中遇到了同样的问题)。

4

1 回答 1

2

如果执行不带参数的 OwinHost.exe,方法名需要是Configuration,而不是Configure

此外,owinhost.exe在根路径 (AKA {projectDir}) 下执行并将构建输出到 /bin,而不是 /bin/debug。当然,这些可以通过开关来配置,OwinHost.exe但如果你想在没有任何开关的情况下运行它,这就是它所需要的。

此处提供了更深入的说明:OWIN 启动类检测和此处:Visual Studio 2013 上 OwinHost.exe 的良好旧 F5 体验

于 2014-02-25T23:00:01.150 回答