【发布时间】:2020-05-30 16:23:07
【问题描述】:
我有一个 .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。
关于如何让这些资源加载到我的 Pipeline 构建中的任何想法?
【问题讨论】:
-
我无法通过 MSBuild 任务重现此问题(不使用 Powershell 任务),请您检查它是否适用于 MSBuild 任务?错误从何而来?构建还是 dotnet 测试?请分享该错误的一些详细错误日志。
-
我没有看到 MSBuild 任务和调用 msbuild.exe 的 Powershell 任务之间的区别。两者的结果是相同的。我想这可能是一个 dotnet 测试问题。我不太确定我可以收集哪些额外的错误日志。问题仍然是 Assembly.GetManifestResourceNames() 在管道上运行时返回 0。我会看看我是否可以找到一些额外的调试来做
-
在我看来,edmx 资源文件实际上并没有嵌入到程序集中
标签: entity-framework azure-devops msbuild resx edmx