13

I have a .NET Core library with the following project.json:

{
  "version": "1.0.0-*",
  "dependencies": {
    "NETStandard.Library": "1.6.0"
  },
  "frameworks": {
    "netstandard1.6": { }
  },
  "scripts": {
    "postcompile": [
      "dotnet pack --no-build --configuration Release",
      "xcopy bin\\Release ..\\..\\lib\\ /Y"
    ]
  }
}

where the postcompile script creates a nuget package which I added as a custom feed in VS, following these instructions. This is because I want to reference it from a Windows Universal App, which cannot be otherwise (yet), according to this question. But when I try it, I get this message:

Package AEther 1.0.0 is not compatible with uap10.0 (UAP,Version=v10.0).
Package AEther 1.0.0 supports: netstandard1.6 (.NETStandard,Version=v1.6)
One or more packages are incompatible with UAP,Version=v10.0.

This is where it stops making sense to me. According to this, it should work fine for netstandard >=1.6.0, while this official table says I need to target netstandard <=1.4.0, but that doesn't change anything. More confusingly, if I downgrade both versions of netstandard (the dependency and the target framework) to, say, 1.5, I still get this exact same error without specifying 1.6 in any of my files.

Update The UWP project.json looks like this

{
  "dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.1"
  },
  "frameworks": {
    "uap10.0": {}
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}

Can someone clear up either

  1. How to reference .Net Core libraries from UWP at all or
  2. What is going on in my specific case?

ANSWER

I solved it adding an import to the UWP app as follows:

{
  "dependencies": {
    "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.1"
  },
  "frameworks": {
    "uap10.0": { import [ "netstandard1.6" ] }
  },
  "runtimes": {
    "win10-arm": {},
    "win10-arm-aot": {},
    "win10-x86": {},
    "win10-x86-aot": {},
    "win10-x64": {},
    "win10-x64-aot": {}
  }
}
Community
  • 1
  • 1
Volker Schmidt
  • 416
  • 3
  • 10

2 Answers2

10

you need to upgrade Microsoft.NETCore.UniversalWindowsPlatform to 5.2.1


Update on July, 15

Ok, here is my result

  1. create a new UWP
  2. Upgrade to 5.2.2, which comes out on July, 14
  3. update project.json, import "netstandard1.6"

    { "dependencies": { "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", "Test": "1.0.0" }, "frameworks": { "uap10.0": { "imports": [ "netstandard1.6" ] } }, "runtimes": { "win10-arm": {}, "win10-arm-aot": {}, "win10-x86": {}, "win10-x86-aot": {}, "win10-x64": {}, "win10-x64-aot": {} } }

  4. create a new dotnet core library

  5. build the library, and generate a nuget package
  6. I am able to reference the .dll file or the nuget package. And i Do get intelligent while typing code
  7. UWP is built and deployed successfully, but once i run it, an exception is thrown enter image description here
Brian Ding
  • 304
  • 3
  • 8
7

This is where it stops making sense to me. According to this, it should work fine for netstandard >=1.6.0, while this official table says I need to target netstandard <=1.4.0, but that doesn't change anything. More confusingly, if I downgrade both versions of netstandard (the dependency and the target framework) to, say, 1.5, I still get this exact same error without specifying 1.6 in any of my files.

Universal Windows Platform maps to netstandard1.4 - neither to 1.6 nor to 1.5. Therefore, your library (called AEther I assume) has a higher requirement than your UWP app.

  1. How to reference .Net Core libraries from UWP at all or

As stated in your linked SO question this is not supported yet in Visual Studio.

I can only guess that it is related to the support by the CLI, which is an open issue. As of today, it is expected to be fixed in the version 5.3 of the Microsoft.NETCore.UniversalWindowsPlatform meta-package - although it was previously expected to be fixed in 5.2.2.

  1. What is going on in my specific case?

NuGet is telling you that your package supports only the netstandard1.6 target framework but not uap10.0. Indeed, if you unpack your .nupkg you'll find your DLL under lib\netstandard1.6.

Since dotnet pack automatically creates the .nuspec from your project.json so you'll need to fix it with the proper framework (eg. netstandard1.4). It'll probably be easier compiling for different frameworks, for instance Portable profiles compatible with .NET Platform Standard.

Community
  • 1
  • 1
jnovo
  • 5,659
  • 2
  • 38
  • 56
  • As I indicated, using netstandard1.4 gives the exact same error (saying netstandard1.6 is required. Hence my confusion). If I have to specifically target uap10.0, how would I do that? – Volker Schmidt Jul 15 '16 at 08:41
  • to clear this up, I was targetting netstandard1.6 because another question here on SO claimed this to be the only way. – Volker Schmidt Jul 15 '16 at 08:43
  • now that I have an answer, I can confirm I DO NOT have to target netstandard1.4 – Volker Schmidt Jul 15 '16 at 08:52
  • You simply need to update from `netstandard1.6`to `netstandard1.4` under `frameworks`. Your NuGet package must have not been re-created or refreshed properly, try increasing the version. – jnovo Jul 15 '16 at 09:15
  • No changes to the NuGet package where necessary. Increasing the version works. – Volker Schmidt Jul 15 '16 at 09:17
  • After editing the `project.json` you need to recreate the `.nupkg` (`dotnet pack`) and install / update it in the UWP app, so yes, a new NuGet package is necessary. Otherwise, you are still using the `netstandard1.6` one... – jnovo Jul 15 '16 at 09:23
  • the project.json I had to edit IS the UWP app, not the library. And yes, I am still using netstandard1.6, and it works. I am as confused as you because it contradicts the docs, but I'm not complaining. – Volker Schmidt Jul 15 '16 at 09:29
  • I was referring to my solution targeting `netstandard1.4`. I think that using `imports` might lead to runtime exceptions due to API incompatibilities, althought they may be corner cases. – jnovo Jul 15 '16 at 09:39
  • Oh, now I see what you mean. But as I said twice, targetting netstandard1.4 did not resolve the error, so sorry, that's not the answer. – Volker Schmidt Jul 15 '16 at 09:41
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/117397/discussion-between-jnovo-and-volker-schmidt). – jnovo Jul 15 '16 at 09:42
  • Agree with @jnovo here. Likely something was missing in your change to ns1.4. You have to be very careful when making changes to a nuget package: nuget will cache the package in both the packages folder and temp. Either change the name or blow-away those caches (nuget.exe locals is a good hammer). – TheESJ Aug 02 '16 at 18:47
  • When we will be able to reference Net standard 1.6 DLL inside UWP? – Adam Paquette Dec 20 '16 at 09:01