Azure DevOps 管道找不到 edmx 资源

Azure DevOps Pipeline not finding edmx resources

我有一个 .Net Core 3.1 MSTest 项目,它调用一个单独的 class 库连接到我的数据库,这是数据库优先完成的,所以我有一个 .edmx 文件。这一切 运行 在本地都很好,但是当我将它推送到我的 Azure DevOps 管道时,我开始遇到 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 Studio19\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。

关于如何让这些资源加载到我的管道构建中,我有什么想法吗?

Azure DevOps Pipeline not finding edmx resources

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

据我所知,dotnet cli 不支持嵌入 edmx 资源。这些类型的文件在 MSBuild props/targets 中受支持,它们不在 CLI 中提供并且仅在完整框架 VS 中提供。

您可以查看 this ticket 了解更多详情。

此项目的剩余工作已在 dotnet/ef6#231 进行跟踪。

希望对您有所帮助。