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
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 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.
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.
Currently, I get the following error:
Could not install package 'csharp-extensions 1.2.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author.
Here is a link to my repo: https://github.com/NullVoxPopuli/csharp-extensions
The Nuget Link: https://www.nuget.org/packages/csharp-extensions/1.2.0
In my project.json, I specify dnx46 and dnxcore50
{
"version": "1.2.0",
"configurations": {
"Debug": {
"compilationOptions": {
"define": [ "DEBUG", "TRACE" ]
}
},
"Release": {
"compilationOptions": {
"define": [ "RELEASE", "TRACE" ],
"optimize": true
}
}
},
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
"System.Reflection": "4.1.0-*",
"xunit": "2.1.0-*",
"xunit.runner.dnx": "2.1.0-*"
},
"commands": {
"run": "csharp_extensions",
"test": "xunit.runner.dnx"
},
"frameworks": {
"dnx46": {
"dependencies": {
"System.Console": "4.0.0-beta-*",
"System.Reflection.TypeExtensions": "4.1.0-beta-*",
"System.Runtime.Extensions": "4.0.11-beta-*",
"System.Dynamic.Runtime": "4.0.11-beta-*",
"Microsoft.CSharp": "4.0.1-beta-*",
"System.IO": "4.0.11-beta-*"
}
},
"dnxcore50": {
"_": "this is the recommended windows runtime",
"dependencies": {
"System.Console": "4.0.0-beta-*",
"System.Reflection.TypeExtensions": "4.1.0-beta-*",
"System.Runtime.Extensions": "(4.0,]",
"System.Dynamic.Runtime": "(4.0.0,]",
"Microsoft.CSharp": "(4.0.0,]",
"System.IO": "(4.0,]"
}
}
},
}
The project I'm trying to install the nuget into is a Class Library targeting .NET Framework 4.6 (and isn't a dnx project)
UPDATE:
This is what happens when I build the nuget package with nuget pack
Looking at your csharp-extensions NuGet package it looks incorrect. It has your project files and no assemblies.
I assume this was generated by running NuGet.exe package package.nuspec. This will not generate a NuGet package that can be used from NuGet.org since there are no assemblies.
If you build your .xproj in Visual Studio it will generate a .nupkg in the artifacts directory for you if you have Product outputs on build checked in the project options, which you have. Unfortunately this .nupkg file, whilst it has assemblies, only has a lib\dnxcore50 directory and NuGet will not allow you to install it into a .NET 4.6 project since NuGet finds them to be incompatible. Using the .nupkg file in the artifacts directory returns the same error. You only seem to be able to install this artifact .nupkg into a DNX project (Console or Web app) but not a DNX Class Library project.
I would take a look at existing NuGet packages and try to generate the same structure. Looking at System.Xml.XmlDocument for example has the new NuGet 3 style directory structure:
\lib
\dotnet
\net46
\ref
\dotnet
\net46
Only the directories above have the System.Xml.XmlDocument.dll in them.
NuGet 2 would have just the lib directory and does not support dotnet as a directory.
Here is the project.json configuration that eventually allowed this nuget to work with non-dnx projects:
https://github.com/NullVoxPopuli/csharp-extensions/blob/2767e8ae87dcc69a14d1a33fd63b9eef364ee1ec/project.json
the key parts were (under frameworks)
"net46": {
"frameworkAssemblies": {
"System.Runtime": {
"type": "build",
"version": ""
}
},
"dependencies": {
"Microsoft.CSharp": "4.0.1-beta-*",
"System.Dynamic.Runtime": "4.0.11-beta-*",
"System.IO": "4.0.11-beta-*",
"System.Reflection.TypeExtensions": "4.1.0-beta-*",
"System.Runtime.Extensions": "4.0.11-beta-*",
}
},
and
using the generic test runners for xunit:
"dependencies": {
"Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
"System.Reflection": "4.1.0-*",
"xunit": "2.1.0-*",
"xunit.runners": "2.0.0",
},