Skip to content

Changes in multi-targeting #425

@jodydonetti

Description

@jodydonetti

Scenario

Some time ago I started enabling multi-targeting on FusionCache: I didn't do that because I needed to special case some parts of the code, but just because I wanted to reduce the amount of explicit dependencies for certain TFMs fater after a request from the community.

But recently community user @nick-randal noticed in #416 that having multi-targeting explicitly towards .NET 6 creates a situation with transitive dependencies where:

  • FusionCache explicitly targets .NET 6 (so, it "supports" it)
  • FusionCache depends on one or more Microsoft core packages with recent versions (eg: System.Collections.Immutable v9)
  • but .NET 6 is not supported anymore (and for a long time)
  • those Microsoft core packages does not explicitly target .NET 6, so they do not officially "support" it

This inadvertently created a not so good situation.

Problem

Because of all of that, an app that still targets .NET 6 and references FusionCache now generates warnings like "System.Collections.Immutable 9.0.0 doesn't support net6.0 and has not been tested with it", which is not great.

This happens because FusionCache is saying "I explicitly support .NET 6" but at the same time it also says "I depend on a v9 core package" while the core package itself is saying "I'm NOT explicitly supporting .NET 6".

Add to this that some people turns on the option "warnings as errors", and we can even get a compile time error.

Solution

From now on FusionCache will have explicit targeting only for currently supported TFMs, which today means no more .NET 3.1, .NET 6 or .NET 7, and for them it will have the minimum set of explicit dependencies.

This, for the main FusionCache package, means going from this:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>netstandard2.0;netcoreapp3.1;net6.0;net7.0;net8.0</TargetFrameworks>
		<!-- ... -->
  	</PropertyGroup>

	<!-- ... -->

	<ItemGroup>
		<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
		<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
		<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
		<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'">
		<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
		<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net6.0'">
		<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
		<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
	</ItemGroup>

</Project>

which generates this:

Image

to this:

<Project Sdk="Microsoft.NET.Sdk">

	<PropertyGroup>
		<TargetFrameworks>netstandard2.0;net8.0;net9.0</TargetFrameworks>
		<!-- ... -->
	</PropertyGroup>

	<!-- ... -->

	<ItemGroup>
		<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.0" />
	</ItemGroup>

	<ItemGroup Condition="'$(TargetFramework)' == 'netstandard2.0'">
		<PackageReference Include="System.Diagnostics.DiagnosticSource" Version="9.0.0" />
		<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.6.0" />
		<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
	</ItemGroup>

</Project>

which generates this:

Image

Consequences?

But wait: does this mean that those older versions of .NET wil not be able to use FusionCache anymore?

Absolutely not!

Since FusionCache targets .NET Standard 2.0, this means that ANY version of .NET compatible with .NET Standard 2.0 (meaning: all versions) will still be able to use FusionCache, just without an explicit "support statement", since those versions are anyway not supported anymore.

This will ideally remove the problems highlighted above, without reducing the amount of .NET versions that can enjoy using FusionCache.

Thoughts?

Any opinion or suggestion is more than welcome, please share!

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions