FluentResults icon indicating copy to clipboard operation
FluentResults copied to clipboard

FluentResults.Extensions.AspNetCore References for .NET 8/9

Open slaneyrw opened this issue 6 months ago • 3 comments

Consider using FrameworkReference for .NET 8 and .NET 9 instead of package reference.

Reference : Use ASP.NET Core APIs in a class library

slaneyrw avatar Jul 09 '25 05:07 slaneyrw

I think that I read some time ago that I can't use FrameworkReference because I also target .NET Standard.

altmann avatar Jul 10 '25 20:07 altmann

Correct, if you only target netstandard. But you are multi-targeting so take advantage of $(TargetFramework) conditions.

If NETStandard 2.x, use package If NET8/9 use framework.

This following is what I use for packages that need switch between packages/framework references.

It would be simpler to target each framework separately ( 1 ItemGroup per target ), but this will automatically work when you start targeting .NET 10.

If you need different packages between 8 and 9 ( and in the future 10 ), then 1 condition per target would be better, but not in this exact use case.

<PropertyGroup>
  <UseFrameworkReference>$([MSBuild]::VersionGreaterThanOrEqual('$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)', '8.0'))</UseFrameworkReference>
</PropertyGroup>

<ItemGroup Condition="$(UseFrameworkReference)">
  <FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>
<ItemGroup Condition="!$(UseFrameworkReference)">
  <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.3.0" />
</ItemGroup>

slaneyrw avatar Jul 13 '25 03:07 slaneyrw

The main FluentResults project could also take advanced of this approach, as .NET 8 and .NET 9 should have higher references for Logging ( 8.0.3 and 9.0.7 respectively ) and I don't think need the task extensions package

slaneyrw avatar Jul 13 '25 03:07 slaneyrw