无法在ASP.NET Core项目中添加对.NET Core类库的引用
问题描述:
我在VS 2015(Update 3)中为它创建了一个新的ASP.NET Core
项目和一个类库。无法在ASP.NET Core项目中添加对.NET Core类库的引用
这是怎么project.json
样子:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
这是ASP.NET项目的project.json
:
{
"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%" ]
}
}
现在我无法将类库来我的网站添加为'依赖不能解决'。
答
我没有在应用程序的dependencies
部分看到对您的库的引用。如果库和应用程序都在同一个解决方案,请确保您使用target: project
像这样:
project.json ASP.NET核心项目:
"dependencies": {
...
"MyLibrary": {
"version": "1.0.0",
"target": "project"
}
}
否则,会的NuGet找你库作为一个包而不是寻找解决方案。
谢谢@Nate Barbettini,它有帮助。现在我的ASP.NET Core项目可以正常工作,但我仍然遇到与Resharper有关的问题。它仍然没有看到图书馆。你有什么机会知道这种治疗方法吗? – alexxjk
@alexxjk不幸的是,这是Resharper的一个已知问题。您必须等待下一个版本,或者获取测试版(EAP)版本。 –
谢谢@Nate!我想我会比... ... – alexxjk