在ASP.NET 5(核心)中添加对类库项目的引用的问题 [英] Issue adding reference to class library project in ASP.NET 5 (Core)
问题描述
首先,我知道以前曾经问过类似的问题,但是现在它们已经过时了,我正在使用Visual Studio 2015 rtm和ASP.NET 5 beta 6。
Hi firstly i know vaguely similar questions have been asked before, but they are outdated now, I am using Visual Studio 2015 rtm and ASP.NET 5 beta 6.
我正在尝试在我的vnext Web应用程序中添加对普通(即非vnext)类库项目的引用。如果执行以下步骤:
I'm trying to add a reference to a normal (i.e. not vnext) class library project to my vnext web application. If I follow these steps:
-
创建一个新的Web应用程序项目
Create a new web app project
从project.json中删除 dnxcore50框架
Remove the "dnxcore50" framework from project.json
为普通类库添加新项目
将类库项目手动移动到/ src文件夹中(否则,我将收到错误消息无法解析依赖MyClassLibrary1> = 1.0.0-*。)
Manually move the class library project into the /src folder (otherwise I get error "The dependency MyClassLibrary1 >= 1.0.0-* could not be resolved.")
添加对此类库的引用
现在它可以构建了,但是如果我尝试添加使用MyClassLibrary1,则表示MyClassLibrary1在当前上下文中不存在。
Now it builds OK, but if I try and add "using MyClassLibrary1" it says MyClassLibrary1 doesn't exist in current context.
如果我然后将类库更改为目标.NET 4 Client配置文件(默认为4.6)可以正常运行,但是.NET 4 full或4.5无法运行。我需要将其设置为4.5或更高版本,因为我需要引用各种需要此功能的软件包。理想情况下,所有内容都只针对4.6。
If I then change the class library to target .NET 4 Client profile (by default it was 4.6) it does work correctly, however .NET 4 full or 4.5 does not work. I need it to be 4.5 or higher as I need to reference various packages that require this. Ideally everything would just target 4.6.
这是我的project.json文件:
This is my project.json file:
{
"webroot": "wwwroot",
"userSecretsId": "aspnet5-WebApplication2-6767111e-0eba-42a4-9d68-4b6c20767518",
"version": "1.0.0-*",
"dependencies": {
"EntityFramework.SqlServer": "7.0.0-beta6",
"EntityFramework.Commands": "7.0.0-beta6",
"Microsoft.AspNet.Mvc": "6.0.0-beta6",
"Microsoft.AspNet.Mvc.TagHelpers": "6.0.0-beta6",
"Microsoft.AspNet.Authentication.Cookies": "1.0.0-beta6",
"Microsoft.AspNet.Authentication.Facebook": "1.0.0-beta6",
"Microsoft.AspNet.Authentication.Google": "1.0.0-beta6",
"Microsoft.AspNet.Authentication.MicrosoftAccount": "1.0.0-beta6",
"Microsoft.AspNet.Authentication.Twitter": "1.0.0-beta6",
"Microsoft.AspNet.Diagnostics": "1.0.0-beta6",
"Microsoft.AspNet.Diagnostics.Entity": "7.0.0-beta6",
"Microsoft.AspNet.Identity.EntityFramework": "3.0.0-beta6",
"Microsoft.AspNet.Server.IIS": "1.0.0-beta6",
"Microsoft.AspNet.Server.WebListener": "1.0.0-beta6",
"Microsoft.AspNet.StaticFiles": "1.0.0-beta6",
"Microsoft.AspNet.Tooling.Razor": "1.0.0-beta6",
"Microsoft.Framework.Configuration.Abstractions": "1.0.0-beta6",
"Microsoft.Framework.Configuration.Json": "1.0.0-beta6",
"Microsoft.Framework.Configuration.UserSecrets": "1.0.0-beta6",
"Microsoft.Framework.Logging": "1.0.0-beta6",
"Microsoft.Framework.Logging.Console": "1.0.0-beta6",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0-beta6"
},
"commands": {
"web": "Microsoft.AspNet.Hosting --config hosting.ini",
"ef": "EntityFramework.Commands"
},
"frameworks": {
"dnx451": {
"dependencies": {
"MyClassLibrary1": "1.0.0-*"
}
}
},
"exclude": [
"wwwroot",
"node_modules",
"bower_components"
],
"publishExclude": [
"node_modules",
"bower_components",
"**.xproj",
"**.user",
"**.vspscc"
],
"scripts": {
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
}
还有我的global.json文件:
And my global.json file:
{
"projects": [
"src",
"test",
"wrap"
],
"sdk": {
"version": "1.0.0-beta6"
}
}
推荐答案
这是我使用beta6进行的操作( UPDATE:RC1 UPDATE 1仍然有效)。
This is how I did it using beta6 (UPDATE: It's still valid for the RC1 UPDATE 1).
- 从您的project.json中删除框架=> dnxcore(无论如何,您都不能使用完整的.net类库将其定位为目标)
- 在目标项目中,右键单击引用 =>添加引用
这会将引用条目添加到您的 project.json 文件。
在后台将dll复制到解决方案中的/ lib目录中,并在/ wrap文件夹中创建仅包含project.json文件的 包装器项目。包装项目记录在这里(虽然不够好): https ://github.com/aspnet/Home/wiki/Project.json-file#bin-syntax-wrapping-a-dll
This will add a reference entry to your project.json file. Behind the scenes the dll is copied over to /lib directory in your solution and a "wrapper project" with only a project.json file is created in /wrap folder. The wrapper project is documented here (not well enough though): https://github.com/aspnet/Home/wiki/Project.json-file#bin-syntax-wrapping-a-dll
就是这样!我刚刚测试了这种情况。希望这会有所帮助。
That's it! I've just tested this scenario. Hope this helps.
这篇关于在ASP.NET 5(核心)中添加对类库项目的引用的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!