2

I am new to .net core. I need some help to configure my project.json file to create a class library with .net core. I actually read a lot of documents, but I am lost since there is an overwhelming amount of things to read. I know that I have to use the NETStandardLibray (https://github.com/dotnet/corefx/blob/master/Documentation/architecture/net-platform-standard.md), but I don't know how to put this in my config.json file.

Here is my config.json file:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },
  "dependencies": {
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0-rc2-3002702"
    },
    "xunit": "2.1.0",
    "dotnet-test-xunit": "1.0.0-rc2-build10025"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dnxcore50",
        "portable-net45+win8"
      ]
    }
  },
  "testRunner": "xunit"
}

I want to build a simple class library to be reused in another projects, and I also want it to have unit tests.

My main difficulty here is about the monikers. They are such a mess. I just want to build a class library that can be used in any platform, but it looks like that I have to choose the platform in my project.json anyways. In the list of deprecated monikers I don't know what moniker I should use. In order to use the NET Standard Library, should I target the platform .NET Standard Application 1.5 that has the nuget identifier netcoreapp1.0, or should I use the platform .NET Platform 5.0 that has the nuget identifier netstandard1.3??? What is the correct platform? Wasn't NETStandard Library supposed to be platform agnostic? And should I put those identifiers in the dependencies or in the frameworks section of my project.json? And whats the difference of those two section at all? I'm totally lost :(

Athari
  • 33,702
  • 16
  • 105
  • 146

1 Answers1

5

Your class library itself should have a framework of netstandard1.3 or whatever version you want - Noda Time is targeting netstandard1.3 for example, as I've found that there's too much missing from netstandard1.0, unfortunately. I'd generally pick the lowest version you're confident in. You don't want netcoreapp1.0 etc, as you're writing a library, not an application.

Your unit tests should be in a separate project, configured as per the xUnit documentation - for example, targeting netcoreapp1.0 and maybe net451 to run on the desktop framework too.

To answer your other concerns, while the .NET Standard Library is platform agnostic (in terms of operating system), you still need to express what version you depend on - if you need something that's only in netstandard1.5, you can't target netstandard1.3, for example.

The part about including Microsoft.NETCore.App etc in the dependencies section is (as I understand it) to avoid having to specify every dependency individually in a modular way. It's a simple way to get started, but you might later want to be more specific, trimming your dependencies to only those you need.

There's definitely a lot still up in the air, a lot of documentation still to be written, and a lot of now-out-of-date documentation and blog posts from the last couple of years... but progress is being made.

Jon Skeet
  • 1,421,763
  • 867
  • 9,128
  • 9,194
  • thank you Jon. For my class library project, should I depend on Microsoft.NetCore.App? Is there a dependency specific for the Standard Library? –  Jun 22 '16 at 16:31
  • @andre: No, as I said before, it's *not* an application, it's a library - so you should use `netstandard1.x`. You could add a dependency to `NetStandard.Library` if you want to - that's the library equivalent, providing all the .NET Standard Library parts. Personally I'd recommend using the fine-grained dependencies from the start though. – Jon Skeet Jun 22 '16 at 16:40
  • I'm still confused :( –  Nov 11 '16 at 14:42
  • @andre: Unfortunately just "I'm still confused" doesn't give me enough detail about what aspect is confusing you. What have you tried and what's giving you problems? – Jon Skeet Nov 11 '16 at 14:43
  • I've gave up some time ago, because of the confusion. This platform is promising, but still very confusing. It could be easier to understand. I'll return to my studies again now. –  Nov 11 '16 at 14:43
  • the names are conflicting when you compare nugget monikers to .net core monikers –  Nov 11 '16 at 14:44
  • Anyway, my main issue is that when I pick netstandar1.3, the compiler just ignores my command and use the latest version instead –  Nov 11 '16 at 14:45
  • And there is the fact that I have litte experience with .net, so, the plataform is very, very, very confusing for newbies studying by itselfs. –  Nov 11 '16 at 14:48
  • And I haven't found in the docs a clear explanation about the differences between the "dependencies" section and the "frameworks" section –  Nov 11 '16 at 14:49
  • @andre: The only part of that that I can really help with is your claim that "the compiler just ignores my command and use the latest version instead". I very much doubt that that's the case, but you should probably ask a new question showing exactly what you mean with a [mcve]. I agree in general that it's a bit confusing at the moment - and bear in mind that `project.json` is going away entirely - but I've explained as best I can in this answer how to create a .NET Core class library. – Jon Skeet Nov 11 '16 at 14:52
  • what will replace the project.json? –  Nov 11 '16 at 14:55
  • @andre: MSBuild files, but hopefully maintaining many of the benefits of project.json. See https://blogs.msdn.microsoft.com/dotnet/2016/05/23/changes-to-project-json/ – Jon Skeet Nov 11 '16 at 14:56