全新(SDK)csproj格式的OWIN应用 [英] OWIN app on new (SDK) csproj format

查看:62
本文介绍了全新(SDK)csproj格式的OWIN应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在将OWIN应用程序转换为新的csproj格式时,遇到了一些问题.第一个问题与更改后的输出目录有关(因为它现在在路径中包括运行时).这引发了以下错误:

While converting an OWIN app to the new csproj format I hit a few issues. The first issue had to do with the changed output directory (since it now includes the runtime in the path). This threw the following error:

Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.Owin.Host.SystemWeb' or one of its dependencies. The system cannot find the file specified.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

我能够通过在Web.config中设置路径来解决此问题:

I was able to fix this by setting the path in the Web.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <probing privatePath="bin/net461" />
  </assemblyBinding>
</runtime>

此后,我现在面临这个问题:

After that I am now confronted with this issue:

The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.EntryPointNotFoundException: The following errors occurred while attempting to load the app.
- No assembly found containing an OwinStartupAttribute.
- The given type or method 'ClientWebAPI.Startup' was not found. Try specifying the Assembly.
To disable OWIN startup discovery, add the appSetting owin:AutomaticAppStartup with a value of "false" in your web.config.
To specify the OWIN startup Assembly, Class, or Method, add the appSetting owin:AppStartup with the fully qualified startup class or configuration method name in your web.config.

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

我已经使用Assembly属性声明了入口点:

I have declared the entry point using the assembly attribute:

[assembly: OwinStartup(typeof(API.Startup))]
namespace API
{
    public class Startup
    { /*...*/ }
}

推荐答案

"Sdk"样式的csproj(有时称为VS2017项目格式)尚不支持ASP.NET 4项目.请参阅以下问题:

The "Sdk" style csproj, sometimes called the VS2017 project format, does not yet support ASP.NET 4 projects. See the following issues:

  • https://github.com/dotnet/sdk/issues/491 (1)
  • https://github.com/dotnet/project-system/issues/2670 (2)

这里有两层问题:(1)MSBuild和(2)Visual Studio.如果您了解目标和导入的工作原理,可以解决(1),并使Sdk样式的csproj适用于Owin项目.

There are two layers of issues here: (1) MSBuild and (2) Visual Studio. If you understand how targets and imports work well enough, you could workaround (1) and make the Sdk style csproj work for an Owin project.

最困难的部分是(2)-Visual Studio.在转换到Sdk样式的项目时,VS在幕后将转换到项目系统的全新实现,该实现在

The more difficult part is (2) - Visual Studio. When switching to the Sdk style project, under the hood, VS is switching to an entirely new implementation of the project system, the one that is open sourced in https://github.com/dotnet/project-system. This project system does not yet fully support ASP.NET 4 projects.

您可以通过使用Microsoft.Owin.SelfHost而不是Microsoft.Owin.Host.SystemWeb来解决(2).为了使Microsoft.Owin.Host.SystemWeb能够正常工作,VS需要知道如何为IIS Express生成web.config和applicationhost.config文件,如何启动IIS Express站点以及在启动后附加到进程.其中大部分没有移植到新的项目系统中,我不确定是否会移植到新的项目系统中.新的项目系统旨在与ASP.NET Core配合使用,该ASP.NET Core使用一种非常不同的方法来启动和配置IIS Express.

You can workaround (2) by using Microsoft.Owin.SelfHost instead of using Microsoft.Owin.Host.SystemWeb. To make using Microsoft.Owin.Host.SystemWeb work, VS needs to know how to generate web.config and applicationhost.config file for IIS Express, how to launch the IIS Express site, and attach to process once launched. Much of that is not ported to the new project system, and I'm not sure if it will be. The new project system was designed to work with ASP.NET Core which uses a very different method for launching and configuring IIS Express.

这篇关于全新(SDK)csproj格式的OWIN应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆