Replies: 2 comments 8 replies
-
|
Hi @digital88 , I looked into AOT compatibility right before releasing v1, and it seemed to be so. |
Beta Was this translation helpful? Give feedback.
-
|
Hi @digital88 ,here's what I've done. I created an AOTTester console app with this code: using ZiggyCreatures.Caching.Fusion;
namespace AOTTester;
internal class Program
{
static async Task Main(string[] args)
{
var cache = new FusionCache(new FusionCacheOptions());
var value = await cache.GetOrSetAsync<int>("foo", async (ctx, ct) => 42);
Console.WriteLine($"VALUE: {value}");
}
}The csproj looks like this: <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<InvariantGlobalization>true</InvariantGlobalization>
<PublishAot>true</PublishAot>
<PublishSingleFile>true</PublishSingleFile>
<SelfContained>true</SelfContained>
<PublishTrimmed>true</PublishTrimmed>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\ZiggyCreatures.FusionCache\ZiggyCreatures.FusionCache.csproj" />
<TrimmerRootAssembly Include="ZiggyCreatures.FusionCache" />
</ItemGroup>
</Project>Some elements may not be 100% needed since they are implicit when you specify others, but still. Then, without even touching FusionCache csproj file, I run this: dotnet publish -c Release --ucr --self-containedwhich told me this: Restore complete (0.4s)
ZiggyCreatures.FusionCache net9.0 succeeded (1.7s) → C:\[...]\ZiggyCreatures.FusionCache\bin\Release\net9.0\win-x64\ZiggyCreatures.FusionCache.dll
AOTTester succeeded (4.6s) → bin\Release\net9.0\win-x64\publish\
Build succeeded in 7.0sNo errors, no warnings, resulting in this: Then I tried adding this to the FusionCache csproj file: <IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsAotCompatible>Then run again the publish: no difference, exactly the same results. So, 2 things:
One last thing. When you say:
Do you mean that if I add multi-targeting for .NET 8/9 to those projects, they too can be used in an AOT scenario? Or would I need to do something else? Thoughts? Btw thanks for pointing this out and for all the info! |
Beta Was this translation helpful? Give feedback.

Uh oh!
There was an error while loading. Please reload this page.
-
Hello.
The main assembly
ZiggyCreatures.FusionCacheseems to be AOT compatible. Almost all other assemblies (exceptSerialization.CysharpMemoryPackandAspNetCore.OutputCaching) targetnetstandard2.0, so they are not AOT compatible.What is AOT: https://learn.microsoft.com/en-us/dotnet/core/deploying/native-aot/
How to mark it:
How to test that it is really compatible: https://learn.microsoft.com/en-us/dotnet/core/deploying/trimming/prepare-libraries-for-trimming (the guide for trimming is same for AOT)
Publish should succeed and produce zero warnings.
The downside of this that if you introduce some code later that breaks AOT (examples here https://learn.microsoft.com/en-us/visualstudio/msbuild/property-functions?view=vs-2022#TargetFramework) this property will produce build warnings.
Beta Was this translation helpful? Give feedback.
All reactions