2

I want to create data small data access library for Sql Server that wraps standard Sql Client classes, and publish it to NuGet. I want to use this NuGet package both in standard and .Net core apps.

I created class library project with some data access code (it uses System, System.Core, and System.Data) and published it to nugget. I have added System, System.Core, and System.Data as NuGet framework dependencies.

UPDATE - described problems both in RC1 and RC2

In RC1 version it works with 4.6 framework, but I had to remove DNX 5 from package.json.

In RC2 version it works with ASPNET Core (.Net Framework) projects, but when I create ASPNET Core (.Net Core), compilation fails:

Error NU1002 The dependency does not support framework .NETCoreApp,Version=v1.0.

Is there any way to create nugget package that works in both versions?

Jovan MSFT
  • 13,232
  • 4
  • 40
  • 55
  • dnx is not a thing anymore. You should move to RC2 and netstandard... – Pawel Jun 03 '16 at 19:39
  • You are right, but this still does not solves the problem. When I create RC2 application, I'm getting the error in package restore: Error NU1002 The dependency does not support framework .NETCoreApp,Version=v1.0. I can fix this if I create nugget package in new project with .NET core class library but again I would have two projects to maintain, one for RC2 and the other for non-core apps. – Jovan MSFT Jun 05 '16 at 21:05

2 Answers2

1

Since .NET Core 1.0 was just released this week, I'll answer the question in the context of the latest version of the framework.

If you are attempting to target both ASP.NET Core 1.0 and .NET 4.5 you have to define both frameworks separately, including all dependencies each framework build would require.

Here is an example project.json file for a class library project that targets .NET Core Standard 1.5, ASP.NET Core 1.0, .NET 4.5, and .NET 4.0 and has a dependency on the System.Linq.Expressions namespace:

{
    "version": "1.0.0-*",

    "frameworks": {
        "netstandard1.5": {
            "imports": "dnxcore50",
            "dependencies": {
                "NETStandard.Library": "1.6.0",
                "System.Linq.Expressions": "4.1.0"
            }
        },
        "netcoreapp1.0": {
            "imports": "dnxcore50",
            "dependencies": {
                "Microsoft.NETCore.App": {
                    "type": "platform",
                    "version": "1.0.0"  
                },
                "System.Linq.Expressions": "4.1.0"
            }
        },
        "net45": {
            "frameworkAssemblies": {
                "System.Linq.Expressions": ""
            }
        },
        "net40": {}
    }
}
Eric Davis
  • 101
  • 4
  • 1
    Thanks, this solved my first part of problem (building separate dlls for separate frameworks). But still I don't understand how to pack these dlls into a single nugget package. Up till not I have deployed one dll to nugget and not I have four versions in four subfolders. If I just add them all to the same nugget, could it be resolved when someone installs it? – Jovan MSFT Jul 30 '16 at 17:02
0

With Visual Studio 2017, you can create a .NET Standard project library. You can select the version in the properties of the project.

Such project looks like this :

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFramework>netstandard1.4</TargetFramework>
    <AssemblyName>MyAssembly</AssemblyName>
    <PackageId>MyPackage</PackageId>
    <GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
    <GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
    <GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
    <Copyright>Copyright</Copyright>
    <Description>Simple Library</Description>
    <Authors>Me</Authors>
    <AssemblyVersion>1.1.0</AssemblyVersion>
    <FileVersion>1.1.0</FileVersion>
    <Version>1.1.0</Version>
    <Company>MyCompany</Company>
  </PropertyGroup>
  <ItemGroup>
    <Folder Include="Properties\" />
  </ItemGroup>
</Project>

In IDE, you have the pack command on the right click menu or you can type this :

msbuild /t:pack myproject.csproj

Only one package.... to rule them all and... :)

Fab
  • 14,327
  • 5
  • 49
  • 68