找不到类型或命名空间名称“OwinStartupAttributeAttribute”

时间:2018-04-14 15:29:01

标签: c# visual-studio-2017

我正在编译一些我没写过的代码。

当我做Build - >构建解决方案我收到此错误:

The type of namespace name 'OwinStartupAttributeAttribute' could not be found (are you missing a using directive or an assembly reference?)

在这行代码中:

using Microsoft.Owin;
using Owin;

[assembly: OwinStartupAttribute(typeof(CCACustomerPayment.Startup))]    

所以,我试着这样做:

PM> install-package microsoft.owin

并收到此错误:

Attempting to gather dependency information for package 'microsoft.owin.4.0.0' with respect to project 'CustomerPayment', targeting '.NETFramework,Version=v4.5'
Gathering dependency information took 1.35 sec
Attempting to resolve dependencies for package 'microsoft.owin.4.0.0' with DependencyBehavior 'Lowest'
One or more unresolved package dependency constraints detected in the existing packages.config file. All dependency constraints must be resolved to add or update packages. If these packages are being updated this message may be ignored, if not the following error(s) may be blocking the current package operation: 'Microsoft.Owin.Host.SystemWeb 3.0.1 constraint: Owin (>= 1.0.0)', 'Microsoft.Owin.Host.SystemWeb 3.0.1 constraint: Microsoft.Owin (>= 3.0.1)', 'Microsoft.Owin.Security 3.0.1 constraint: Owin (>= 1.0.0)', 'Microsoft.Owin.Security 3.0.1 constraint: Microsoft.Owin (>= 3.0.1)', 'Microsoft.Owin.Security.Cookies 2.1.0 constraint: Owin (>= 1.0.0)', 'Microsoft.Owin.Security.Cookies 2.1.0 constraint: Microsoft.Owin (>= 2.1.0)', 'Microsoft.Owin.Security.OAuth 2.1.0 constraint: Owin (>= 1.0.0)', 'Microsoft.Owin.Security.OAuth 2.1.0 constraint: Microsoft.Owin (>= 2.1.0)'
Resolving dependency information took 0 ms
Resolving actions to install package 'microsoft.owin.4.0.0'
Resolved actions to install package 'microsoft.owin.4.0.0'
Retrieving package 'Microsoft.Owin 4.0.0' from 'nuget.org'.
Retrieving package 'Owin 1.0.0' from 'nuget.org'.
Adding package 'Owin.1.0.0' to folder 'C:\Users\ME\source\Customer\customerpayment\CustomerPayment\packages'
Added package 'Owin.1.0.0' to folder 'C:\Users\Me\source\Customer\customerpayment\CustomerPayment\packages'
Added package 'Owin.1.0.0' to 'packages.config'
Successfully installed 'Owin 1.0.0' to CustomerPayment
Install failed. Rolling back...
Package 'Microsoft.Owin.4.0.0 : Owin [1.0.0, )' does not exist in project 'CustomerPayment'
Removed package 'Owin.1.0.0' from 'packages.config'
Package 'Microsoft.Owin.4.0.0 : Owin [1.0.0, )' does not exist in folder 'C:\Users\Me\source\ Customer\customerpayment\CustomerPayment\packages'
Removing package 'Owin.1.0.0' from folder 'C:\Users\ME\source\Customer\customerpayment\CustomerPayment\packages'
Removed package 'Owin.1.0.0' from folder 'C:\Users\ME\source\Customer\customerpayment\CustomerPayment\packages'
Executing nuget actions took 529.79 ms
install-package : Could not install package 'Microsoft.Owin 4.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.5', but the package 
does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
At line:1 char:1
+ install-package microsoft.owin
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], Exception
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

Time Elapsed: 00:00:01.9633227

我还尝试添加--version 4.5和其他变体,但这也不起作用。

当我查看Project -> Add Reference时,我看不到Microsoft.owin的任何选项。

如何编译此代码?

3 个答案:

答案 0 :(得分:1)

这是我根据@HansPassant建议解决问题的方法:

我使用以下步骤更改为.Net 4.6.1:

  1. 右键单击项目
  2. 选择Properties
  3. 设置应用程序 - >目标框架至4.6.1
  4. 选择Tools -> NuGet Package Manager -> Package Manager Console
  5. 输入install-package microsoft.owin
  6. 期望看到安装成功

答案 1 :(得分:0)

microsoft.owin不是要启动项目,还要添加Microsoft.Owin.Host.SystemWeb。 有了它,你应该能够启动它。

答案 2 :(得分:0)

据我记忆,您可能还需要参考Microsoft.Owin.Host.SystemWebDownload it from NuGet