问题补充参考类libary项目在ASP.NET 5(核心) [英] Issue adding reference to class libary project in ASP.NET 5 (Core)
问题描述
嗨首先,我隐约知道类似的问题已经被问过,但他们现在已经过时,我使用Visual Studio 2015年RTM和ASP.NET 5测试版6。
我试图为正常(即非vnext)类库项目的引用添加到我的vnext Web应用程序。如果我请按照下列步骤:
-
创建一个新的Web应用程序项目
-
卸下project.json了dnxcore50框架
-
添加一个新项目,一个正常的类库
-
手动类库项目移入/ src文件夹(否则我得到错误的依存MyClassLibrary1> = 1.0.0- *无法得到解决。)
-
添加到这个类库的引用
现在它建立好了,但如果我尝试,并添加使用MyClassLibrary1它说MyClassLibrary1不在目前的情况下存在。
如果我然后更改类库面向.NET 4客户端配置文件(默认为4.6),它工作正常,但是.NET 4个整体或4.5不起作用。我需要它是4.5,因为我需要引用这需要各种包高。理想的情况是一切都只是针对4.6。
这是我的project.json文件:
{
根目录:wwwroot的
userSecretsId:aspnet5-WebApplication2-6767111e-0eba-42a4-9d68-4b6c20767518,
版本:1.0.0- *, 依赖:{
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
}, 命令:{
网络:Microsoft.AspNet.Hosting --config hosting.ini
EF:EntityFramework.Commands
}, 构架: {
dnx451:{
依赖:{
MyClassLibrary1:1.0.0- *
} }
}, 排除:[
wwwroot的
node_modules
bower_components
]
publishExclude:[
node_modules
bower_components
**。xproj
**。用户,
**。vspscc
]
脚本:{
prepublish:故宫安装,亭子安装,大口喝干净,吞掉分钟]
}
}
和我global.json文件:
{
工程:
SRC
测试,
包
]
SDK:{
版本:1.0.0-beta6
}
}
这是我做到了用beta6(更新:它仍然是有效的RC1更新1 )
。- 删除框架=>从project.json dnxcore(你可以使用反正完整的.NET类库没有目标的话)
- 在目标项目中右键单击引用=>添加引用
- 导航和选择参考DLL要添加。
这将参考条目添加到您的 project.json 文件。
幕后的DLL被复制到/ lib目录在您的解决方案和一个包装项目中/包文件夹中创建只有一个project.json文件。该包装项目记录在这里(没有很好,虽然不够):<一href=\"https://github.com/aspnet/Home/wiki/Project.json-file#bin-syntax-wrapping-a-dll\">https://github.com/aspnet/Home/wiki/Project.json-file#bin-syntax-wrapping-a-dll
这就是它!我刚刚测试过这种情况。希望这有助于。
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.
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:
Create a new web app project
Remove the "dnxcore50" framework from project.json
Add a new project for a normal class library
Manually move the class library project into the /src folder (otherwise I get error "The dependency MyClassLibrary1 >= 1.0.0-* could not be resolved.")
Add a reference to this class library
Now it builds OK, but if I try and add "using MyClassLibrary1" it says MyClassLibrary1 doesn't exist in current context.
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.
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" ]
}
}
And my global.json file:
{
"projects": [
"src",
"test",
"wrap"
],
"sdk": {
"version": "1.0.0-beta6"
}
}
This is how I did it using beta6 (UPDATE: It's still valid for the RC1 UPDATE 1).
- Remove frameworks => dnxcore from your project.json (you can't target it anyway using full .net class libraries)
- In your target project right click on References => Add Reference
- Navigate and select reference dll you want to add.
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.
这篇关于问题补充参考类libary项目在ASP.NET 5(核心)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!