0
votes

I have a .Net Core 3.1 MSTest project that calls a separate class library that connects to my database, which was done database-first so I have a .edmx file. It all runs fine locally, but when I push it out to my Azure DevOps Pipeline I start getting a Unable to load the specified metadata resource. exception. I've tested this out by putting in a bit of code to print out all the resources in the assembly

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);
}

The result on my local computer prints out what I expect

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

However, the same run on my Pipeline shows 0 resources

There are 0 resources in the assembly

My build process locally and on my pipeline are the exact same

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

Just to make sure the resources actually exist on my Azure Build agent I've added that 2nd powershell command to find my .csdl, .msl, and .ssdl files, and sure enough they do exist

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 

These files are located in $(Build.SourcesDirectory)\MyProject\Project.Models\obj\Debug\edmxResourcesToEmbed

And the property looks to be correctly set in my .csproj

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

I don't use .edmx database designs often, so I'm unfamiliar on how it is suppose to handle the resources, are they suppose to get compiled into the assembly, or are they just loaded at runtime? My build process both locally and in my Pipeline both show:

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.

Not sure what that indicates, but since it occurs on both I'm assuming its not part of the issue. The only other difference that I can think of is my Azure Pipeline uses Visual Studio 2019 Enterprise, while my local build uses Visual Studio 2019 Community.

Any ideas on what I can do to get these resources to load on my Pipeline build?

1
I could not reproduce this issue with MSBuild task(Not use Powershell task), would you please check if it works fine with MSBuild task? And where is error comes from? The build or the dotnet test? Please share some detailed error log for that error.Leo Liu-MSFT
I'm not seeing a difference between the MSBuild task and the Powershell Task calling msbuild.exe. The result is the same for both. I suppose it could be a dotnet test issue. I'm not too sure what additional error logging I can collect. The issue is is still Assembly.GetManifestResourceNames() returning 0 when running on the pipeline. I'll see if I can find some additional debugging to doDillon Drobena
It just appears to me that the edmx resource files aren't actually getting embedded into the assemblyDillon Drobena

1 Answers

1
votes

Azure DevOps Pipeline not finding edmx resources

This issue should comes from the dotnet test.

AFAIK, dotnet cli does not support embed edmx resources. These types of files are supported in MSBuild props/targets that don't ship in the CLI and only ship in full framework VS.

You could check this ticket for some more details.

And the remaining work for this is already tracked at dotnet/ef6#231.

Hope this helps.