使用xbuild和mono时未嵌入Entity Framework元数据工件 [英] Entity Framework metadata artifact not embeded when using xbuild and mono

查看:64
本文介绍了使用xbuild和mono时未嵌入Entity Framework元数据工件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试在Linux或Windows环境上使用EntityFramework和MySQL时,遇到了以下问题:

When I try and use EntityFramework and MySQL on a Linux or Windows environment I run into the following problem:

项目1:包含EntityFramework edmx和使用dbcontext类插入更新数据的逻辑项目2:参考项目1.

Project 1: Contains EntityFramework edmx and logic to insert update data using the dbcontext class Project 2: References Project 1.

当我使用msbuild构建解决方案时,EntityFramework元数据文件被嵌入到Project1.dll中.

When I build the solution using msbuild the EntityFramework metadata files are embeded in Project1.dll

当我在Linux环境或Windows环境中使用xbuild进行干净的构建时,EntityFramework元数据文件丢失了

When I do a clean build with xbuild in a Linux environment or in a Windows environment the EntityFramework metadata files are missing

运行应用程序时,出现以下错误:

When you run the application you get the following error:

无法加载指定的元数据资源.

Unable to load the specified metadata resource.

我正在使用单声道版本 4.2.2

I am using mono version 4.2.2

有人知道使用xbuild时嵌入EntityFramework元数据文件的解决方案吗?

推荐答案

在单声道嵌入Entity Framework元数据工件之前,我已经实现了以下解决方法

I have implemented the following workaround until mono embeds the Entity Framework metadata artifacts

  1. 第1步-将EntityFramework模型的元数据工件处理属性从嵌入到输出程序集中" 更新为复制到输出目录"

这会将元数据工件文件复制到包含.edmx(Project1)的项目的bin文件夹中.

This copies the metadata artifact files to the bin folder of the project containing the .edmx(Project1)

  1. Step2-将以下构建后事件添加到引用项目(Project2),以将元数据工件文件复制到其bin中.您可以将它们添加到.csproj项目文件的末尾.将 Project1 替换为您的项目名称.

<PropertyGroup>
   <PostBuildEvent Condition=" '$(OS)' != 'Unix' ">copy /Y   "$(ProjectDir)..\Project1\bin\Debug\Models\*" "$(ProjectDir)\bin\Debug\"  </PostBuildEvent>
   <PostBuildEvent Condition=" '$(OS)' == 'Unix' ">cp -a "$(ProjectDir)../Project1/bin/Debug/Models/." "$(ProjectDir)bin/Debug/"  </PostBuildEvent>
</PropertyGroup>

  • 第3步-更新您的连接字符串

  • Step3 - Update your connection string

    来自

    <add name="EntityframeworkTestEntities" connectionString="metadata=res://*/EntityFrameworkTestModel.csdl|res://*/EntityFrameworkTestModel.ssdl|res://*/EntityFrameworkTestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=EntityframeworkTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

    <add name="EntityframeworkTestEntities" connectionString="metadata=EntityFrameworkTestModel.csdl|EntityFrameworkTestModel.ssdl|EntityFrameworkTestModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=.;initial catalog=EntityframeworkTest;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
    

  • 这篇关于使用xbuild和mono时未嵌入Entity Framework元数据工件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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