我有一个.Net Core 3.1 MSTest项目,该项目调用一个连接到我的数据库的单独的类库,该类库首先在数据库中完成,所以我有一个.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 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。
关于如何使这些资源加载到管道构建中的任何想法?
Azure DevOps Pipeline未找到edmx资源
此问题应该来自dotnet测试。
AFAIK,dotnet cli不支持嵌入的edmx资源。MSBuild道具/目标中不支持这些类型的文件,该工具不在CLI中提供,而仅在完整框架VS中提供。
您可以检查此票以获取更多详细信息。
剩下的工作已经在dotnet / ef6#231进行了跟踪。
希望这可以帮助。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句