Skip to content

Add AOT and trim analyzers #130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<IsPackable>true</IsPackable>
<PublishAot Condition="'$(TargetFrameworkIdentifier)' == '.NETCoreApp' AND $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '8.0'))">true</PublishAot>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we not targeting .NET 8 yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Not sure why net7.0 was chosen as the target here specifically, but generally we want to target the lowest framework version possible.

</PropertyGroup>

<!-- Packaging-related properties -->
Expand Down
2 changes: 2 additions & 0 deletions src/Passwordless/Passwordless.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
<PropertyGroup>
<TargetFrameworks>net462;net6.0;net7.0;netstandard2.0</TargetFrameworks>
<IsPackable>true</IsPackable>
<IsTrimmable Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))">true</IsTrimmable>
<IsAotCompatible Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))">true</IsAotCompatible>
</PropertyGroup>

<!-- Packaging-related properties -->
Expand Down
10 changes: 9 additions & 1 deletion src/Passwordless/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Options;
using Passwordless;
Expand Down Expand Up @@ -31,12 +32,16 @@
/// <summary>
/// Adds and configures Passwordless-related services.
/// </summary>
#if NET7_0_OR_GREATER
[RequiresDynamicCode("This method is incompatible with native AOT compilation.")]
[RequiresUnreferencedCode("This method is incompatible with assembly trimming.")]
#endif
public static IServiceCollection AddPasswordlessSdk(
this IServiceCollection services,
IConfiguration configuration)
{
services.AddOptions<PasswordlessOptions>()
.Configure(configuration.Bind)

Check warning on line 44 in src/Passwordless/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / format

Using member 'Microsoft.Extensions.Configuration.ConfigurationBinder.Bind(IConfiguration, Object)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. Cannot statically analyze the type of instance so its members may be trimmed.
.Validate(options => !string.IsNullOrEmpty(options.ApiSecret), "Passwordless: Missing ApiSecret");

services.RegisterDependencies();
Expand All @@ -44,18 +49,21 @@
return services;
}


/// <summary>
/// Adds and configures Passwordless-related services.
/// </summary>
/// <param name="services"></param>
/// <param name="section"></param>
/// <returns></returns>
#if NET7_0_OR_GREATER
[RequiresDynamicCode("This method is incompatible with native AOT compilation.")]
[RequiresUnreferencedCode("This method is incompatible with assembly trimming.")]
#endif
public static IServiceCollection AddPasswordlessSdk(
this IServiceCollection services,
string section)
{
services.AddOptions<PasswordlessOptions>().BindConfiguration(section);

Check warning on line 66 in src/Passwordless/ServiceCollectionExtensions.cs

View workflow job for this annotation

GitHub Actions / format

Using member 'Microsoft.Extensions.DependencyInjection.OptionsBuilderConfigurationExtensions.BindConfiguration<TOptions>(OptionsBuilder<TOptions>, String, Action<BinderOptions>)' which has 'RequiresUnreferencedCodeAttribute' can break functionality when trimming application code. TOptions's dependent types may have their members trimmed. Ensure all required members are preserved.

services.RegisterDependencies();

Expand Down
Loading