ASP.NET 5 Web项目和实体框架在单独的项目中 [英] ASP.NET 5 Web project and Entity Framework in separate projects

查看:101
本文介绍了ASP.NET 5 Web项目和实体框架在单独的项目中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我已经更新了我的项目以使用新的ASP.NET 5空预览模板。 p>

我已经设法完成所有的项目建设,但是当我运行我的网站时,我收到这个错误


当前的运行时目标框架与
'MY.WEB.NAMESPACE'不兼容。



当前运行时目标框架:'DNX,版本= v4.5.1(dnx451)'类型:
CLR架构:x86版本:1.0.0-beta5-12103



请确保运行时匹配框架在
project.json中指定


我迄今为止看到的所有示例似乎都具有相同的EntityFramework项目,但我正在使用EntityFramework(目前版本6),在一个单独的项目。我的项目如下



基础架构 - 任何项目引用的有用功能



实体 - 我的POCO对象



数据 - 我的DbContext类和其他数据库特定代码



服务 - 我的服务添加/更新实体,还参考SimpleValidation
进行验证



Web - 我的Web应用程序,由WebApi和angularJs组成。



现在我为每个项目都有一个project.json文件,看起来像这样



基础设施

  {
:1.0.0- *,
description:my.namespace.Infrastructure,
authors:[me],
tags:[ ],
projectUrl:,
licenseUrl:,

依赖:{
System.Collections:4.0 .11-beta-23225,
System.Linq:4.0.1-beta-23225,
System.Threading:4.0.11-beta-23225,
System.Runtime:4.0.21-beta-23225,
Microsoft.CSharp 4.0.1-beta-23225,
Humanizer:1.37.7
},

框架:{
net46: {}
}
}

ENTITES(POCOS)

  {
version:1.0.0- *,
description:my.namespace.Entities ,
authors:[me],
tags:[],
projectUrl:,
licenseUrl ,

依赖:{
System.Collections:4.0.11-beta-23225,
System.Linq:4.0.1-beta -23225,
System.Threading:4.0.11-beta-23225,
System.Runtime:4.0.21-beta-23225,
Microsoft .CSharp:4.0.1-beta-23225
},

框架:{
net46:{}
}
}

DATA(DBCONTEXT)

  {
version:1.0.0- *,
description:my.namespace.Data,
authors [我],
标签:[],
projectUrl:,
licenseUrl:,

依赖关系:{
System.Collections:4.0.11-beta-23225,
System.Linq:4.0.1-beta-23225,
系统.Threading:4.0.11-beta-23225,
System.Runtime:4.0.21-beta-23225,
Microsoft.CSharp:4.0.1-beta -23225,
DbExtensions:5.1.0,
my.namespace.Entities:1.0.0- *,
my.namespace.Infrastructure: 1.0.0- *,
EntityFramework:6.1.3
},

框架:{
net46:{}
}
}

SERVICE

  {
version:1.0.0- *,
description:my.namespace.Service,
作者:[我],
标签:[],
projectUrl:,
licenseUrl:,

依赖:{
System.Collections:4.0.10-beta-23019,
System.Linq 4.0.0-beta-23019,
System.Threading:4.0.10-beta-23019,
System.Runtime:4.0.10-beta-23019
Microsoft.CSharp:4.0.0-beta-23019,
FluentValidation:5.6.2,
my.namespace.Entities:1.0.0 - *,
my.namespace.Data:1.0.0- *,
my.namespace.Infrastructure:1.0.0- *,
ncalc :1.3.8
},

框架:{
net46:{}
}
}

我的web应用程序project.json看起来像这样

  {
webroot:wwwroot,
version:1.0.0- *,
description:my.namespace .Web
作者:[我],

依赖:{
Microsoft.AspNet.Server.IIS:1.0.0- beta5,
Microsoft.AspNet.Serve r.WebListener:1.0.0-beta5,
Microsoft.AspNet.Mvc:6.0.0-beta5,
AutoMapper:4.0.4
},

命令:{
web:Microsoft.AspNet.Hosting --config hosting.ini
},

框架:{
dnx5:{
dependencies:{
my.namespace.Infrastructure:1.0.0- *,
my。 namespace.Entities:1.0.0- *,
my.namespace.Data:1.0.0- *,
my.namespace.Service:1.0.0- *
}
}
},

publishExclude:[
node_modules,
bower_components,
**。xproj,
**。user,
**。vspscc
],
exclude:[
wwwroot ,
node_modules,
bower_components
]
}

现在这一切都似乎修好了,没有错误,但是我试图运行,我得到上面的消息。我看到另一个帖子



当我更改为dnxcore5,我得到这个





编辑2:



我有更新了我所有的项目,使用dnx50并删除了dnxcore50。我仍然得到相同的错误。它必须与我的安装有关....但是我不知道...

解决方案

第一个目标 dnx-clr-win-x86 (很可能是您的情况下的beta5),因为您希望在IIS上使用实体框架运行此操作。检查您的解决方案属性另请参阅解决方案项目文件夹中的 global.json 。请注意,运行时目标是 clr

 sdk:{
version :1.0.0-beta5,
runtime:clr,
architecture:x86
}
pre>

将dnx5(这不存在)更改为dnx46,并从所有project.json文件中删除dnxcore50。

 框架:{
dnx46:{
dependencies:{}
}
},

向您的Web项目DNX_IIS_RUNTIME_FRAMEWORK添加一个环境变量: DNX46



一个附注,beta7已经出来,我建议你使用而不是beta5,并记得升级你的dnvm。


Where to begin... This has had me all day.

I have updated my projects to use the new ASP.NET 5 Empty Preview Template.

I have managed to get all my projects building, but when i run my website, i get this error

The current runtime target framework is not compatible with 'MY.WEB.NAMESPACE'.

Current runtime Target Framework: 'DNX,Version=v4.5.1 (dnx451)' Type: CLR Architecture: x86 Version: 1.0.0-beta5-12103

Please make sure the runtime matches a framework specified in project.json

All the examples i have seen so far, seem to have both EntityFramework in the same project, but i am using EntityFramework (currently version 6), in a separate project. My Projects are as follows

Infrastructure - Helpful functions, referenced by any project

Entities - My POCO objects

Data - My DbContext class and other Database specific code

Service - My services to add/update entities, also references SimpleValidation for my validation

Web - My web application, which consists of WebApi and angularJs.

Now i have a project.json file for each project, which looks like so

INFRASTRUCTURE

{
    "version": "1.0.0-*",
    "description": "my.namespace.Infrastructure",
    "authors": [ "me" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "System.Collections": "4.0.11-beta-23225",
        "System.Linq": "4.0.1-beta-23225",
        "System.Threading": "4.0.11-beta-23225",
        "System.Runtime": "4.0.21-beta-23225",
        "Microsoft.CSharp": "4.0.1-beta-23225",
        "Humanizer": "1.37.7"
    },

    "frameworks": {
        "net46": { }
    }
}

ENTITES (POCOS)

{
    "version": "1.0.0-*",
    "description": "my.namespace.Entities",
    "authors": [ "me" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "System.Collections": "4.0.11-beta-23225",
        "System.Linq": "4.0.1-beta-23225",
        "System.Threading": "4.0.11-beta-23225",
        "System.Runtime": "4.0.21-beta-23225",
        "Microsoft.CSharp": "4.0.1-beta-23225"
    },

    "frameworks": {
        "net46": { }
    }
}

DATA (DBCONTEXT)

{
    "version": "1.0.0-*",
    "description": "my.namespace.Data",
    "authors": [ "me" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "System.Collections": "4.0.11-beta-23225",
        "System.Linq": "4.0.1-beta-23225",
        "System.Threading": "4.0.11-beta-23225",
        "System.Runtime": "4.0.21-beta-23225",
        "Microsoft.CSharp": "4.0.1-beta-23225",
        "DbExtensions": "5.1.0",
        "my.namespace.Entities": "1.0.0-*",
        "my.namespace.Infrastructure": "1.0.0-*",
        "EntityFramework": "6.1.3"
    },

    "frameworks": {
        "net46": { }
    }
}

SERVICE

{
    "version": "1.0.0-*",
    "description": "my.namespace.Service",
    "authors": [ "me" ],
    "tags": [ "" ],
    "projectUrl": "",
    "licenseUrl": "",

    "dependencies": {
        "System.Collections": "4.0.10-beta-23019",
        "System.Linq": "4.0.0-beta-23019",
        "System.Threading": "4.0.10-beta-23019",
        "System.Runtime": "4.0.10-beta-23019",
        "Microsoft.CSharp": "4.0.0-beta-23019",
        "FluentValidation": "5.6.2",
        "my.namespace.Entities": "1.0.0-*",
        "my.namespace.Data": "1.0.0-*",
        "my.namespace.Infrastructure": "1.0.0-*",
        "ncalc": "1.3.8"
    },

    "frameworks": {
        "net46": { }
    }
}

My web application, project.json looks like this

{
    "webroot": "wwwroot",
    "version": "1.0.0-*",
    "description": "my.namespace.Web",
    "authors": [ "me" ],

    "dependencies": {
        "Microsoft.AspNet.Server.IIS": "1.0.0-beta5",
        "Microsoft.AspNet.Server.WebListener": "1.0.0-beta5",
        "Microsoft.AspNet.Mvc": "6.0.0-beta5",
        "AutoMapper": "4.0.4"
    },

    "commands": {
        "web": "Microsoft.AspNet.Hosting --config hosting.ini"
    },

    "frameworks": {
        "dnx5": {
            "dependencies": {
                "my.namespace.Infrastructure": "1.0.0-*",
                "my.namespace.Entities": "1.0.0-*",
                "my.namespace.Data": "1.0.0-*",
                "my.namespace.Service": "1.0.0-*"
            }
        }
    },

    "publishExclude": [
        "node_modules",
        "bower_components",
        "**.xproj",
        "**.user",
        "**.vspscc"
    ],
    "exclude": [
        "wwwroot",
        "node_modules",
        "bower_components"
    ]
}

Now this all seems to build fine, with no errors, but when i try to run, i get the above message. I saw another post here which suggests adding an environment variable, but this doesnt seem to work.

If i remove all the references to my other projects, comment out all code that references the other projects, and then change frameworks tag to this, the site loads.

"frameworks": {
    "dnx45": {
        "dependencies": {

        }
    }
},

Any help would be greatly appreciated.

EDIT.

Here is my project properties

When i change to dnxcore5, i get this

EDIT 2:

I have updated all my projects to use dnx50 and dropped dnxcore50. I still get the same error. It must be something to do with my installation....But what i have no idea...

解决方案

First target dnx-clr-win-x86 (most likely beta5 in your case) since you want to run this on IIS with Entity Framework. Check your solution properties. Also have a look at global.json in your Solution Items folder. Please note that runtime targets clr.

"sdk": {
    "version": "1.0.0-beta5",
    "runtime": "clr",
    "architecture": "x86"
}

Change dnx5 (this doesn't exist) to dnx46 and remove dnxcore50 from all project.json files.

"frameworks": {
    "dnx46": {
        "dependencies": {}
    }
},

Add an environment variable to your web project "DNX_IIS_RUNTIME_FRAMEWORK" : "DNX46"

A side note, beta7 is already out and I suggest you use that rather than beta5 and also remember to upgrade your dnvm.

这篇关于ASP.NET 5 Web项目和实体框架在单独的项目中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆