在 Class 库项目中引用 ASP.NET 核心应用程序
Referencing a ASP.NET Core application in Class Library project
我创建了一个 ASP.NET Core
应用程序:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Core": "7.0.0-beta8",
"EntityFramework.SqlServer.Design": "7.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Abstractions": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.DataAnnotations": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"System.IdentityModel.Tokens.Jwt": "5.0.0-rc1-211161024",
"Microsoft.IdentityModel.Protocols": "2.0.0-rc1-211161024",
"ClassLibrary1": "1.0.0-*",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
"Microsoft.AspNet.Identity.Owin": "2.2.1",
"Microsoft.AspNet.WebApi.Owin": "5.2.3",
"Microsoft.Owin.Cors": "3.0.1",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Owin": "1.0.0",
"Thinktecture.IdentityModel": "3.6.1",
"Thinktecture.IdentityModel.Client": "4.0.1"
},
"frameworkAssemblies": {
"System.Web": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
然后我添加了一个单元测试项目:
{
"version": "1.0.0-*",
"description": "InviteMoi.Test Class Library",
"authors": [ "lamloumiafif" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"dependencies": {
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
},
"dependencies": {
"NUnit": "3.2.1",
"EntityFramework.InMemory": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
}
}
问题是我想在测试项目中添加web应用的引用,没有成功,出现异常提示ASP.NET Core的版本不对更高的出现。
那么我该如何解决这个问题?
在您的单元测试中 project.son 删除 dotnet5.4 并将 net451 更改为 dnx451,就像在应用程序中一样。单元测试项目是应用程序,就像网络应用程序一样
我创建了一个 ASP.NET Core
应用程序:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"EntityFramework.Commands": "7.0.0-beta8",
"EntityFramework.SqlServer": "7.0.0-beta8",
"EntityFramework.Core": "7.0.0-beta8",
"EntityFramework.SqlServer.Design": "7.0.0-beta8",
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Abstractions": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.DataAnnotations": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.WebApiCompatShim": "6.0.0-rc1-final",
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
"Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final",
"Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
"System.IdentityModel.Tokens.Jwt": "5.0.0-rc1-211161024",
"Microsoft.IdentityModel.Protocols": "2.0.0-rc1-211161024",
"ClassLibrary1": "1.0.0-*",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"Microsoft.AspNet.Identity.EntityFramework": "2.2.1",
"Microsoft.AspNet.Identity.Owin": "2.2.1",
"Microsoft.AspNet.WebApi.Owin": "5.2.3",
"Microsoft.Owin.Cors": "3.0.1",
"Microsoft.Owin.Host.SystemWeb": "3.0.1",
"Owin": "1.0.0",
"Thinktecture.IdentityModel": "3.6.1",
"Thinktecture.IdentityModel.Client": "4.0.1"
},
"frameworkAssemblies": {
"System.Web": "4.0.0.0"
}
}
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
然后我添加了一个单元测试项目:
{
"version": "1.0.0-*",
"description": "InviteMoi.Test Class Library",
"authors": [ "lamloumiafif" ],
"tags": [ "" ],
"projectUrl": "",
"licenseUrl": "",
"frameworks": {
"net451": {
"dependencies": {
}
},
"dotnet5.4": {
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-23516",
"System.Collections": "4.0.11-beta-23516",
"System.Linq": "4.0.1-beta-23516",
"System.Runtime": "4.0.21-beta-23516",
"System.Threading": "4.0.11-beta-23516"
}
}
},
"dependencies": {
"NUnit": "3.2.1",
"EntityFramework.InMemory": "7.0.0-rc1-final",
"EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-rc1-final",
"InviteMoi.BLL": "1.0.0-*",
"InviteMoi.DAL": "1.0.0-*"
}
}
问题是我想在测试项目中添加web应用的引用,没有成功,出现异常提示ASP.NET Core的版本不对更高的出现。
那么我该如何解决这个问题?
在您的单元测试中 project.son 删除 dotnet5.4 并将 net451 更改为 dnx451,就像在应用程序中一样。单元测试项目是应用程序,就像网络应用程序一样