首页 > 解决方案 > Azure DevOps Pipeline 找不到 edmx 资源

问题描述

我有一个 .Net Core 3.1 MSTest 项目,它调用一个单独的类库来连接到我的数据库,这是数据库优先完成的,所以我有一个 .edmx 文件。它在本地运行良好,但是当我将其推送到我的 Azure DevOps Pipeline 时,我开始遇到Unable to load the specified metadata resource.异常。我已经通过输入一些代码来打印出程序集中的所有资源来对此进行测试

var resources = (Assembly with EDMX).Assembly.GetManifestResourceNames();
System.Console.WriteLine("There are " + resources.Length + " resources in the assembly");
foreach (var resource in resources)
{
    System.Console.WriteLine(resource);
}

我本地计算机上的结果打印出我期望的结果

There are 3 resources in the assembly
Model.csdl
Model.msl
Model.ssdl

但是,我的管道上的相同运行显示 0 个资源

There are 0 resources in the assembly

我在本地和管道上的构建过程完全相同

task: PowerShell@2
inputs:
targetType: 'inline'
script: |
  & "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\msbuild.exe" $(Build.SourcesDirectory)\MyProject\MyProject.sln
  dir $(Build.SourcesDirectory)\MyProject -include ('*.csdl', '*.msl', '*.ssdl') -recurse
  & "C:\hostedtoolcache\windows\dotnet\dotnet.exe" test $(Build.SourcesDirectory)\MyProject\Project.Tests\Project.Tests.csproj

只是为了确保资源确实存在于我的 Azure Build 代理上,我添加了第二个 powershell 命令来查找我的 .csdl、.msl 和 .ssdl 文件,并且确实它们确实存在

Mode                LastWriteTime         Length Name                                                                  
----                -------------         ------ ----                                                                  
-a----        5/30/2020   3:54 PM          30772 Model.csdl                                                   
-a----        5/30/2020   3:54 PM          10993 Model.msl                                                    
-a----        5/30/2020   3:54 PM          23351 Model.ssdl 

这些文件位于$(Build.SourcesDirectory)\MyProject\Project.Models\obj\Debug\edmxResourcesToEmbed

并且该属性看起来在我的 .csproj 中设置正确

  <ItemGroup>
      <EntityDeploy Include="ProjectModels.edmx">
          <Generator>EntityModelCodeGenerator</Generator>
          <LastGenOutput>ProjectModels.Designer.cs</LastGenOutput>
      </EntityDeploy>
  </ItemGroup>

我不经常使用 .edmx 数据库设计,所以我不熟悉它应该如何处理资源,它们是否应该被编译到程序集中,或者它们只是在运行时加载?我在本地和管道中的构建过程都显示:

Skipping target "EntityDeployNonEmbeddedResources" because it has no outputs.
EntityDeployEmbeddedResources:
Processing 1 EDMX files.
Starting to process input file 'ProjectModels.edmx'.
Finished processing input file 'ProjectModels.edmx'.
Finished processing 1 EDMX files.

不确定这表明什么,但由于它发生在两者上,我假设它不是问题的一部分。我能想到的唯一其他区别是我的 Azure Pipeline 使用 Visual Studio 2019 Enterprise,而我的本地构建使用 Visual Studio 2019 Community。

关于我可以做些什么来让这些资源加载到我的管道构建中的任何想法?

标签: entity-frameworkazure-devopsmsbuildresxedmx

解决方案


Azure DevOps Pipeline 找不到 edmx 资源

这个问题应该来自 dotnet 测试。

AFAIK,dotnet cli 不支持嵌入 edmx 资源。MSBuild props/targets 支持这些类型的文件,这些文件不在 CLI 中提供,仅在完整框架 VS 中提供。

您可以查看这张票以获取更多详细信息。

对此的剩余工作已经在dotnet/ef6#231进行了跟踪。

希望这可以帮助。


推荐阅读