Entity Framework metadata artifact not embeded when using xbuild and mono

☆樱花仙子☆ 提交于 2021-02-19 07:36:25

问题


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

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

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

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.

I am using mono version 4.2.2

Does anybody know a solution for embedding the EntityFramework metadata files when using xbuild?


回答1:


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

  1. Step1 - Update your EntityFramework Model's Metadata Artifact Processing property from "Embed in Output Assembly" to "Copy to Output Directory"

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

  1. Step2 - Add the following post build events to the referencing project(Project2) to copy the metadata artifact files to its bin. You can add them to the end of the .csproj project file. Replace Project1 with the name of your project.

    <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>
    
  2. Step3 - Update your connection string

    from

    <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" />
    

    to

    <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" />
    


来源:https://stackoverflow.com/questions/35547289/entity-framework-metadata-artifact-not-embeded-when-using-xbuild-and-mono

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!