EntityFramework Commands in ASP.Net 5 Class Library Package?
Asked Answered
J

1

10

I am trying to develop my first ASP.Net web application and in my solution I have two projects. A Web Application and Class Library (Package). When I build the ASP.Net 4.5 version of this application I put my Entity Framework 6 entities into a class library, so I am doing that in the ASP.Net 5 version. The problem is when I install EntityFramework.Commands to the class library I get the error:

The dependency EntityFramework.Command 7.0.0-rc1-final in Project DBEntities does not support framework .NetPlatform, Version = 5.4

My understanding from this SO question is that dotnet5.4 is the new .Net 5 which is supposed to be supported by EF7.

Here is my project.json file:

{
  "version": "1.0.0-*",
  "description": "FFInfo.DAL Class Library",
  "authors": [ "Mathew" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.CSharp": "4.0.1-beta-23516",
                "System.Collections": "4.0.11-beta-23516",
                "System.Linq": "4.0.1-beta-23516",
                "System.Runtime": "4.0.21-beta-23516",
                "System.Threading": "4.0.11-beta-23516"
            }
        }
    },
    "dependencies": {
        "EntityFramework.Commands": "7.0.0-rc1-final",
        "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
    }
}

Did I install the wrong package, is EF7 changed so much that I am building out the class wrong, or am I missing something in my json file?

EDIT: New project.json file based off suggestions

{
    "version": "1.0.0-*",
    "description": "FFInfo.DAL Class Library",
    "authors": [ "Mathew" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",
    "frameworks": {
        "dotnet5.4": {
            "dependencies": {
                "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
                "Microsoft.Dnx.Runtime": "1.0.0-*",
                "Microsoft.Extensions.CommandLineUtils.Sources": {
                    "version": "1.0.0-*",
                    "type": "build"
                },
                "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
                "System.Console": "4.0.0-*",
                "System.IO.FileSystem": "4.0.1-*"
            }
        },
        "netcore50": {
            "bin": {
                "assembly": "lib\\netcore50\\_._"
            }
        },
        "dependencies": {
            "EntityFramework.Commands": "7.0.0-rc1-final",
            "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final"
        }
    }
}
Johnnie answered 19/12, 2015 at 12:42 Comment(3)
The framework dotnet5.4 is synonym of dnxcore50 and not dnx451 (see the official announcement). I personally find the changes of names vary bad. I would recommend you to rename dotnet5.4 to dnxcore50 first of all. Probably you should use net451 or dnx451 instead of "frameworks"."dotnet5.4"."dependencies" if your class library is for ASP.Net 4.5 mostly? In any way I would recommend you to add "dnx451": { } (or "net451": { }) back to "frameworks". If you would be able to reproduce the problem I can try to help more.Prodigal
@Prodigal I don't want it to target .Net 4.5 I want it to target .Net 5.0 core This Class Library is for the ASP.Net 5 version of my web app.Johnnie
I think that your problem could be solved by renaming "dotnet5.4" to "dnxcore50". If it would work I would post my answer with more detailed explanation. I think that you can remove additionally all "dependencies" included in "frameworks"."dotnet5.4" ("frameworks"."dnxcore50") and probably use the common "dependencies", but include only really required dependencies. The optimization of `"frameworks"``is independent from your main problem.Prodigal
P
15

I suppose that the reason of your problem have pure technical nature. The announcement declares renaming of dnx451 to net451 and dnxcore50 to dotnet5.4, but one recommend to use such renaming only for class libraries (which you publich on NuGet for example to share with other). If I understand you correctly, that you develop application which uses class libraries and thus you should use dnxcore50 instead of dotnet5.4. Thus you need just rename the string "dotnet5.4" to the string "dnxcore50" in the fileproject.json` to fix the problem.

Independent from the above recommendation I want to add my understanding of your problem, why you get the error about EntityFramework.Command 7.0.0-rc1-final.

I understand the renaming of frameworks as the step in direction to future changes which plan Microsoft. On the other side all names of frameworks will be interpreted just as different names. I suggest you to compare the information about the dependencies displayed on the page https://www.nuget.org/packages/EntityFramework.Commands/7.0.0-rc1-final from the corresponding information from https://www.nuget.org/packages/EntityFramework.MicrosoftSqlServer/7.0.0-rc1-final. The dependencies of EntityFramework.MicrosoftSqlServer (which have no problems with the usage of dotnet5.4) looks like on the picture

enter image description here

I marked read the part responsible for dotnet5.4. On the other side the dependencies of EntityFramework.Commands looks like on the picture below:

enter image description here

where there are no ".NETPlatform 5.4" section which corresponds the new name dotnet5.4.

I suppose that it's a bug in the part of project.json of EntityFramework.Commands:

"netcore50": {
  "bin": {
    "assembly": "lib\\netcore50\\_._"
  }
}

I suppose that one have to change netcore50 to dotnet5.4 in the lines to support new framework name dotnet5.4 correctly. One chould replace the content of "netcore50" to the copy from dnxcore50 (see the lines):

"dotnet5.4": {
  "dependencies": {
    "Microsoft.AspNet.Hosting.Abstractions": "1.0.0-*",
    "Microsoft.Dnx.Runtime": "1.0.0-*",
    "Microsoft.Extensions.CommandLineUtils.Sources": {
      "version": "1.0.0-*",
      "type": "build"
    },
    "Microsoft.Extensions.PlatformAbstractions": "1.0.0-*",
    "System.Console": "4.0.0-*",
    "System.IO.FileSystem": "4.0.1-*"
  }
}

Probably one should event increase some version numbers of the dlls referenced above, but you still will be not able to use EntityFramework.Commands under "dotnet5.4" till the new fixed version will be published.

UPDATED: I posed the issue to the EntityFramework developer team. I'll include the response from Microsoft on the issue after I'll get it.

Prodigal answered 19/12, 2015 at 13:41 Comment(9)
But EntityFramework.Commands is not a Class Library, its an application...Girandole
@StaffordWilliams: I think that there are some differences in terminology currently. For me DLL is not Application. Independent from the classification of "EntityFramework.Commands" it have to be compiled with "dotnet5.4" as "frameworks" in project.json if one want to allow to use it in applications, which use it and be compiled for dotnet5.4 too. You can try to reproduce the problem in some project which use EntityFramework. You will get the error by renames dnxcore50 to dotnet5.4.Prodigal
I tried to copy the lies you linked to but now I get The dependecny Microsoft.Extensions.CommandLineUtils.Sources >= 1.0.0-* could not be resolved. and the same error for Microsoft.Dnx.Runtime so I don't think just replacing is the solutionJohnnie
@MatthewVerstraete: Where you tried to copy the lines (in the source of EntityFramework.Commands or in your project)? What I mean that the developers of EntityFramework.Commands have to create new version which support dotnet5.4, but you have no chance to do this. The way which I recommended to you: renaming "dotnet5.4" to "dnxcore50" in your project.json.Prodigal
@MatthewVerstraete: Youe last project.json contains many errors: 1) you should remove "netcore50" part; 2) you should rename "dotnet5.4" to "dnxcore50"; 3) you should move "dependencies": { "EntityFramework.Commands": "7.0.0-rc1-final", "EntityFramework.MicrosoftSqlServer": "7.0.0-rc1-final" } on the correct place out of "frameworks", like you had originally. The "dependencies" describes common dependency of your project which are independent from the framework.Prodigal
@Prodigal Sorry, I don't under stand all your suggested changes. Can you amend your answer with an example project.json. I got the remove netcore50 and the rename but not sure where you want me to move the other stuff to.Johnnie
@MatthewVerstraete: Just get the project.json, which you originally posted, and rename the string "dotnet5.4" to "netcore50". Nothing more. I formulated the suggestion in the first paragraph of my answer. All other long text of my answer, which I included in my answer, just described the reason of the problem.Prodigal
@Prodigal Sorry was reading to much into your answer. I reverted back to my original project.json file and did the rename. The errors are now gone and the project builds. Thank youJohnnie
@MatthewVerstraete: You are welcome! I know my problem with writing too long and too detailed answers. :-) I will inform you about the progress of the issue which I posted.Prodigal

© 2022 - 2024 — McMap. All rights reserved.