merken / Prise

A .NET Plugin Framework.
https://merken.github.io/Prise
MIT License
361 stars 39 forks source link

Plugin framework version is newer than the host #34

Closed ayfie-frank-gynnild closed 4 years ago

ayfie-frank-gynnild commented 4 years ago

This is more of question really, if anyone stumbled across this problem:

I run into an issue when trying to use load plug-ins from a test assembly, using dotnet test. I've trived with both MSTest and xUnit, but essentially run into a mismatch of the .NETCoreApp version. The contract, plug-in and the host have the <TargetFramework>netcoreapp3.1</TargetFramework> set.

Error:

 Test method Acme.LoadDummyPlugin threw exception: 
    Prise.PrisePluginException: Plugin framework version .NETCoreApp,Version=v3.1 is newer than the host .NETCoreApp,Version=v2.1. Please upgrade the host to load this plugin.

When I convert from a unit test to a console app, everything runs fine. But I'd love to create unit tests for the plug-ins.

Has anyone experienced this problem?

merken commented 4 years ago

Hi,

Prise gets the runtime information via the Host Framework Provider https://github.com/merken/Prise/blob/master/src/Prise/Providers/HostFrameworkProvider.cs

I assume your unit test project is 2.1? You can fix this by providing the value of the framework attribute of the host assembly, please see this configuration here: https://github.com/merken/Prise/blob/master/src/Tests/Prise.IntegrationTestsHost/Startup.cs#L72

Create an AppHostFrameworkProvider: https://github.com/merken/Prise/blob/master/src/Tests/Prise.IntegrationTestsHost/Custom/AppHostFrameworkProvider.cs

See if that works for you...

ayfie-frank-gynnild commented 4 years ago

Hi Maarten, and thanks! I can confirm that was the missing piece for me, it works like a charm now from xUnit.

The problem seems to be this: Although my unit test library is set to .NET Core 3.1, the Microsoft test host assembly (testhost.dll) that's hosting the tests, is still only targeting .NET Core 2.1 and that's what's being picked by the default implementation.

See https://github.com/microsoft/vstest/blob/master/src/testhost/testhost.csproj: <TargetFrameworks>netcoreapp2.1;net451;net452;net46;net461;net462;net47;net471;net472;net48</TargetFrameworks>

This issue can be closed, although it would be good to have the documentation for this around. Might be easier to onboard new members to this great project. 😄 👍