Can not add reference to .NET Core class library in ASP.NET Core project

匿名 (未验证) 提交于 2019-12-03 07:50:05

问题:

I've created a new ASP.NET Core project and a class library for it in VS 2015 (Update 3).

This is how project.json looks like:

    {       "version": "1.0.0-*",        "dependencies": {         "NETStandard.Library": "1.6.0"       },        "frameworks": {         "netstandard1.6": {           "imports": "dnxcore50"         }       }     } 

And this is a project.json of the ASP.NET Project:

{   "dependencies": {     "Microsoft.NETCore.App": {       "version": "1.0.0",       "type": "platform"     },     "Microsoft.AspNetCore.Mvc": "1.0.0",     "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",     "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",     "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",     "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",     "Microsoft.Extensions.Configuration.Json": "1.0.0",     "Microsoft.Extensions.Logging": "1.0.0",     "Microsoft.Extensions.Logging.Console": "1.0.0",     "Microsoft.Extensions.Logging.Debug": "1.0.0",     "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0"   },    "tools": {     "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"   },    "frameworks": {     "netcoreapp1.0": {       "imports": [         "dotnet5.6",         "portable-net45+win8"       ]     }   },    "buildOptions": {     "emitEntryPoint": true,     "preserveCompilationContext": true   },    "runtimeOptions": {     "configProperties": {       "System.GC.Server": true     }   },    "publishOptions": {     "include": [       "wwwroot",       "Views",       "Areas/**/Views",       "appsettings.json",       "web.config"     ]   },    "scripts": {     "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]   } } 

Now I can't add my class library to my site as 'dependency can't be resolved'.

回答1:

I didn't see a reference to your library in your application's dependencies section. If your library and your application are in the same solution, make sure you use target: project like so:

project.json of ASP.NET Core project:

"dependencies": {     ...     "MyLibrary": {         "version": "1.0.0",         "target": "project"     } } 

Otherwise, NuGet will look for your library as a package instead of looking in the solution.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!