I have created a .NetCore Class Library which I have tested in same solution with .NetCore Console Application (and it works just fine), however when I try referencing it inside another (ASP.NET Core Web Application) solution as a NuGet package I always get a error
NU1002 The dependency YoutubeExtractorCore 0.0.6 does not support framework .NETCoreApp,Version=v1.0.
I have added the netcoreapp1.0 in the class library project.json, which looks like this:
{
"title": "YoutubeExtractorCore",
"description": ".NET Core library used for extracting information about Youtube videos",
"version": "0.0.6-*",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Newtonsoft.Json": "9.0.1"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50",
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
}
},
"netstandard1.6": {
"imports": "dnxcore50"
}
}
}
I spent this afternoon trying to fix the problem but I cannot even understand why this error occurs.
I finally figured out what was causing the problem. The NuGet package I created was packed with nuget.exe manually, and for some reason did not have the frameworks and their dependencies listed. I fixed the package by executing dotnet pack on the class library and this produced correcly packed NuGet package.
Related
I am trying to create a nuget for a class library which I want to be consumed across different applications. This class library is in .net core (4.5.1 framework).
The project.json looks like below:
{
"version": "1.0.0",
"dependencies": {
"NETStandard.Library": "1.6.0",
"Microsoft.AspNetCore.Diagnostics.Abstractions": "1.0.0",
"Microsoft.AspNetCore.Http": "1.0.0",
"log4net": "2.0.8"
},
"description": "Logging from .net core",
"frameworks": {
"netstandard1.6": {
"imports": [ "dnxcore50" ]
}
}
}
I build my class library and create a nuget package and put it in my internal repository. I created nuget package using 2 different ways:
create a .nuspec file( command : nuget spec) and pack the .nuspec file (command nuget pack projectname.nuspec) -> results in a .nupkg file
Command : dotnet pack project.json -> results in .nupkg and .sysmbols.nupkg files
When I try to restore this package from my repo into another application, I get error :
for nuget created with method 1 :
Package TestLib 1.0.0 is not compatible with netstandard1.6 (.NETStandard,Version=v1.6). Package TestLib 1.0.0 supports: net (.NETFramework,Version=v0.0)
One or more packages are incompatible with .NETStandard,Version=v1.6.
When I looked into References tree in Solution explorer, I see that the error is on my referenced class library package with message :
NU1002 The dependency TestLib does not support framework .NetStandard, version =v1.6
For method 2:
Restore will be successful, but I do not get/use any classes from the library. Basically an empty dll reference.
The project.json of my application is simple and straight.
{
"version": "1.0.0-*",
"buildOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.1"
},
"TestLib": "1.0.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": "dnxcore50"
}
}
}
I am going clue less why this behaviour!! Why I am not able to restore a .net core library nuget into another. I also tried restoring to a . net core console application, .net core web application all with same results.
I am using VS2015 ENterprise edition with .netCore tools Preview 2
I'v created a web application with net core and with this project
"frameworks": {
"net461": {
"dependencies": {
"Core": {
"target": "project"
}
}
}
},
Then I've crated a class library net core with this project
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
}
but when I try to add the class project to web application, VS2015 tell me
The following project are not supported as reference.
WebApplication:
.NETFramework, Version=v4.6.1
ClassLibrary:
.NETStandard, Version=v1.6
How can I add class library to main project?
If you want to target .NET framework 4.6.1, your class library must be .NET Standard 1.4 or lower as suggested on official docs - How to target the .NET Standard
1) Create .NET core class library. project.json looks like this-
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.4": {
"imports": "dnxcore50"
}
}
}
2) In ASP.NET Core application (.NET framework), it can reference like below-
"frameworks": {
"net461": {
"dependencies": {
"ClassLibrary1": {
"target": "project"
}
}
}
},
You have to start your project as a dotnetcore project (see image below) because it seems like you want to add a framework 4.6 file to your dotnetcore application.
for more information about dotnetcore compatibulity check this post
Compatibility between dotnetcore and framework 4.5
I have .NET Core project with the following project.json:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
I have created nuget package (see postcompile above) and published in nuget.
Then I've created standard 4.6.2 library, but cannot install package - there is error that package doesn't contain valid assemblies for target .NET Framework 4.6.2.
How should I prepare nuget package to make it available in standard library? I thiough that target NETStandard is valid for both - core and standard projects.
If you check the compatibility matrix for .Net Standard it looks like .Net 4.6.2 only supports NetStandard 1.5. Under frameworks you are targeting 1.6 that is marked for vNext.
See here for the compatibility matrix to know what version you should target
So in other words if you change your config to the following you should be able to reference the library freely:
"frameworks":
{
"netstandard1.5": {}
}
You don't need to add another framework type like suggested in another answer since 4.6.2 should be able to reference a 1.5 Standard.
you should be able to add support for .Net Framework 4.6.2 with adding "net462" to your project.json:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.6": {
"imports": "dnxcore50"
},
"net462": {
"dependencies" : {
"System.Runtime": "4.0.20.0" // you may have to add this
// add here your dependencies
}
}
},
"scripts": {
"postcompile": [
"dotnet pack --no-build --configuration %compile:Configuration%"
]
}
}
see also my project.json on github with a few supported frameworks
I have a asp core web app with
"frameworks": {
"net452": {}
},
And I have also Class Library (.NET Core).
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"net452": {}
}
}
}
The question is, how can I add web app project reference to class library? Should I import some .net framework or use .net standard ?
Now I have a error message when I was trying to add reference to class library project.
The following projects are not supported as references:
"webprojectname" has target frameworks that are incompatible with
targets in current project "classlibraryprojectname"
"classlibraryprojectname": .NETCoreApp, Version=v1.0 "webprojectname":
.NETFramework, Version=v4.5.2
EDIT: Updated in accordance with changes to the question.
So I don't keep filling the comments section, your project.json's should look like this:
Web App (you will also have other dependencies not shown here):
"dependencies": {
"YourClassLibrary": "1.0.0-*"
},
"frameworks": {
"net452": { }
}
Class Library:
{
"version": "1.0.0-*",
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netstandard1.2": { }
}
}
Note: if your class library depends on something higher than netstandard1.2, then you will either have to increment the .Net Framework in your web app to match the NETSTandard you're using (as per previously linked docs), or you will need to cross-compile the class library like so:
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.5": {
"dependencies": {
"NETStandard.Library": "1.6.0"
}
},
"net452": { }
}
}
Using the first suggestion, your application produces one assembly for your class library, using this second method your class library will be compiled twice (one for netstandard1.5, one for net452). When your web app tries to resolve the class library, it realises it can't use netstandard1.5 (which targets net462), so falls back to the net452 assembly. Note however that using this second option is usually indicative of something not being right with your project structure, and should only be used if you know what you're doing and why (in my opinion).
The NETStandard.Library dependency shown is essential a NuGet bundle that pulls down the necessary CoreFX packages. If you get errors like "Cannot find Microsoft.CSharp" it's usually because you haven't pulled down the default packages. You can instead pull down only the CoreFX packages you want, such as System.Collections but this is a more advanced technique.
Hopefully that helps clear things up?
I have a previously generated DLL with some enterprise code that I would like to reuse in a .NETCore project. However, since the original DLL was created and compiled using .NETFramework 4.5 I am not able to directly add the dll as a reference.
I created a nuget package containing my dll as shown here. After that, I am able to add such package to the project. However, I am having the following error:
"The dependency MyAssembly.dll does not support framework
.NETCoreApp,Version=v1.0"
I have already tried referencing .NETCore.Portable.Compatibility but I dont think that is the right way to go. How can I use this dll on my code?
This is what my project.json looks like after adding the Nuget package.
{
"version": "1.0.0-*",
"dependencies": {
"MyAssembly.dll": "1.0.0",
"Microsoft.EntityFrameworkCore": "1.0.0",
"Microsoft.EntityFrameworkCore.SqlServer": "1.0.0",
"Microsoft.NETCore.Portable.Compatibility": "1.0.1",
"NETStandard.Library": "1.6.0"
},
"frameworks": {
"netcoreapp1.0": {
"imports": [ "dnxcore50", "portable-net451+win8" ]
}
}
}
You can add more than one frameworks in project json file in your .netcore class library. By default you will have .net core framework. Just add comma and add your required .net framework.
{
"version": "1.0.0-*",
"frameworks": {
"netstandard1.6": {
"dependencies": {
"NETStandard.Library": "1.6.0"
},
"imports": "dnxcore50"
},
"net45": {
"dependencies": {},
"imports": "net452"
}
}
}
If your .NET 4.5 dll is not compiled as PCL, you cannot reference it from project that targets netcoreapp1.0. It should be re-compiled as portable library or target netstandard API set.