Open drew-cooper opened 1 year ago
Looking at the build artifacts on Ubuntu I see this:
$ ls bin/Debug/net472
Microsoft.VisualStudio.CodeCoverage.Shim.dll Newtonsoft.Json.dll PactNet.Abstractions.dll nunit.engine.core.dll pact_ffi.dll
NUnit3.TestAdapter.dll PactMultitargetTest.dll PactNet.dll nunit.engine.dll
NUnit3.TestAdapter.pdb PactMultitargetTest.pdb nunit.engine.api.dll nunit.framework.dll
Note the pact_ffi.dll
which is the Windows native component.
The culprit appears to be this build/net461/PactNet.targets
file in the Nuget package:
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<!-- This file supports .Net Framework, which doesn't automatically unpack the runtimes folder -->
<ItemGroup>
<Content Include="$(MSBuildThisFileDirectory)..\..\runtimes\win-x64\native\pact_ffi.dll">
<Link>pact_ffi.dll</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Visible>false</Visible>
</Content>
</ItemGroup>
</Project>
So, when building net461 or higher (in our case net472) we unconditionally copy in the Windows native component.
Manually copying in the Linux component fixes the test issue:
$ cp ~/.nuget/packages/pactnet/4.5.0/runtimes/linux-x64/native/libpact_ff
i.so bin/Debug/net472
$ dotnet test --no-build
Test run for /mnt/c/my-repo-dir/PactMultitargetTest/bin/Debug/net472/PactMultitargetTest.dll (.NETFramework,Version=v4.7.2)
Microsoft (R) Test Execution Command Line Tool Version 17.5.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 595 ms - PactMultitargetTest.dll (net472)
Test run for /mnt/c/my-repo-dir/PactMultitargetTest/bin/Debug/netcoreapp3.1/PactMultitargetTest.dll (.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 17.5.0 (x64)
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 507 ms - PactMultitargetTest.dll (netcoreapp3.1)
I would be happy to provide a PR to add similar platform detection as in PactNet.csproj
to the PactNet.targets
file to copy the appropriate binary for the system on which the tests are being built.
Currently .Net Framework is only supported on Windows, hence the unconditional copy in the targets file that you've found.
I've marked the issue as a feature request if Mono support is needed, but unsure on the relative priority of that given .Net Core has full Linux support and is the recommended framework going forwards.
Thanks for the response. I'll have a workaround available to me soon so probably not that critical.
We have a multi-targeted test project (
net472
andnetcoreapp3.1
) containing PACT Consumer tests. The tests fail to run for thenet472
on our Ubuntu-based build image. The image has dotnet SDK 3.1 and 6.0 and Mono 6.6.0 installed.Minimal viable repro:
PactMultitargetTest.csproj:
SimpleTest.cs:
This runs as expected on Windows:
On Ubuntu I get this: