1

I have an existing open source library that I have written in .NET 4.5 that I want to create a NuGet from. The problem is that this NuGet package will only be available for .NET 4.5 applications.

What I want to do is have support for both .NET 4.5 and .NET Core on the same NuGet (I already seen packages that do that line JSON.NET) - how can I add support to an existing NuGet? And how do I support in a single class library to multiple .NET versions?

3
  • Unless there is a strong need from your users, wait. That's what I did for my open source projects. The current tooling is too much a pain and you probably don't want to waste your time. A few promises have been made recently by Microsoft, blogs.msdn.microsoft.com/dotnet/2016/09/26/… Commented Oct 6, 2016 at 4:57
  • @LexLi thanks. can you elaborate what are the current tools that are avilable? Commented Oct 6, 2016 at 5:49
  • dot.net has all you need. Commented Oct 6, 2016 at 6:38

1 Answer 1

1

You may keep using csproj for net45 target and add project.json that targets both "net45" and "netstandard1.x" frameworks (use project.json of my library as a sample):

  "frameworks": {
    "net45": {
      "frameworkAssemblies": {
        "System.Data": "",
        "System.ComponentModel.DataAnnotations" : ""
      },
      "buildOptions": {
        "define": []
      }
    },
    "netstandard1.5": {
      "dependencies": {
        "NETStandard.Library": "1.6.0",
        "System.Data.Common": "4.1.0",
        "System.Reflection": "4.1.0",
        "System.Reflection.Primitives": "4.0.1",
        "System.Threading": "4.0.11",
        "System.Threading.Tasks": "4.0.11",
        "System.ComponentModel.Annotations": "4.1.0" 
      },
      "buildOptions": {
        "define": [ "NET_STANDARD" ]
      }
    }

Note that you can define conditional compilation constants for net45 or netcore specific code snippets.

When you have project.json, you may prepare nuget package that includes both net45 and netstandard builds with the following command:

> dotnet pack --configuration Release

Don't forget that "dotnet pack" doesn't use information from nuspec file and all metadata should be present in project.json.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.