Skip to content

Commit e86d3c0

Browse files
authored
Westinm/trimming (#2210)
1 parent 9a31c6b commit e86d3c0

31 files changed

+270
-8
lines changed

Directory.Build.props

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@
2929
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
3030
</PropertyGroup>
3131

32+
<PropertyGroup Condition="'$(TargetFramework)' == 'net6.0' or '$(TargetFramework)' == 'net7.0'">
33+
<IsTrimmable>true</IsTrimmable>
34+
</PropertyGroup>
35+
3236
<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
3337
<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
3438
</PropertyGroup>
@@ -105,17 +109,17 @@
105109
<MicrosoftAspNetCoreAuthenticationJwtBearerVersion>5.0.12-*</MicrosoftAspNetCoreAuthenticationJwtBearerVersion>
106110
<MicrosoftAspNetCoreAuthenticationOpenIdConnectVersion>5.0.12-*</MicrosoftAspNetCoreAuthenticationOpenIdConnectVersion>
107111
<MicrosoftExtensionsCachingMemoryVersion>5.0.0</MicrosoftExtensionsCachingMemoryVersion>
108-
<!-- Microsoft.Extensions.Hosting 5.* are obsoleted -->
112+
<!-- Microsoft.Extensions.Hosting 5.* are obsoleted -->
109113
<MicrosoftExtensionsHostingVersion>6.0.0</MicrosoftExtensionsHostingVersion>
110114
<MicrosoftAspNetCoreDataProtectionVersion>5.0.8</MicrosoftAspNetCoreDataProtectionVersion>
111115
<SystemSecurityCryptographyXmlVersion>6.0.1</SystemSecurityCryptographyXmlVersion>
112-
116+
113117
<!-- CVE-2022-34716 due to DataProtection 5.0.8 -->
114118
<MicrosoftExtensionsLoggingVersion>5.0.0</MicrosoftExtensionsLoggingVersion>
115119
<SystemTextEncodingsWebVersion>6.0.0</SystemTextEncodingsWebVersion>
116-
120+
117121
<!-- Microsoft.Extensions.Configuration.Binder 6.* are obsoleted -->
118-
<MicrosoftExtensionsConfigurationBinderVersion>6.0.0</MicrosoftExtensionsConfigurationBinderVersion>
122+
<MicrosoftExtensionsConfigurationBinderVersion>6.0.0</MicrosoftExtensionsConfigurationBinderVersion>
119123
<MicrosoftExtensionsDependencyInjectionVersion>2.1.0</MicrosoftExtensionsDependencyInjectionVersion>
120124
</PropertyGroup>
121125

src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.HttpMethods.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Net.Http;
67
using System.Security.Claims;
78
using System.Threading;
@@ -14,6 +15,9 @@ namespace Microsoft.Identity.Web
1415
internal partial class DownstreamApi : IDownstreamApi
1516
{
1617
/// <inheritdoc/>
18+
#if NET6_0_OR_GREATER
19+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
20+
#endif
1721
public async Task<TOutput?> GetForUserAsync<TOutput>(
1822
string? serviceName,
1923
Action<DownstreamApiOptionsReadOnlyHttpMethod>? downstreamApiOptionsOverride = null,
@@ -41,6 +45,9 @@ ex is InvalidOperationException
4145
}
4246

4347
/// <inheritdoc/>
48+
#if NET6_0_OR_GREATER
49+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
50+
#endif
4451
public async Task<TOutput?> GetForUserAsync<TInput, TOutput>(
4552
string? serviceName,
4653
TInput input,
@@ -76,6 +83,9 @@ ex is InvalidOperationException
7683
}
7784

7885
/// <inheritdoc/>
86+
#if NET6_0_OR_GREATER
87+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
88+
#endif
7989
public async Task<TOutput?> GetForAppAsync<TOutput>(
8090
string? serviceName,
8191
Action<DownstreamApiOptionsReadOnlyHttpMethod>? downstreamApiOptionsOverride = null,
@@ -102,6 +112,9 @@ ex is InvalidOperationException
102112
}
103113

104114
/// <inheritdoc/>
115+
#if NET6_0_OR_GREATER
116+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
117+
#endif
105118
public async Task<TOutput?> GetForAppAsync<TInput, TOutput>(
106119
string? serviceName,
107120
TInput input,
@@ -136,6 +149,9 @@ ex is InvalidOperationException
136149
}
137150

138151
/// <inheritdoc/>
152+
#if NET6_0_OR_GREATER
153+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
154+
#endif
139155
public async Task PostForUserAsync<TInput>(
140156
string? serviceName,
141157
TInput input,
@@ -169,6 +185,9 @@ ex is InvalidOperationException
169185
}
170186

171187
/// <inheritdoc/>
188+
#if NET6_0_OR_GREATER
189+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
190+
#endif
172191
public async Task<TOutput?> PostForUserAsync<TInput, TOutput>(
173192
string? serviceName,
174193
TInput input,
@@ -204,6 +223,9 @@ ex is InvalidOperationException
204223
}
205224

206225
/// <inheritdoc/>
226+
#if NET6_0_OR_GREATER
227+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
228+
#endif
207229
public async Task PostForAppAsync<TInput>(
208230
string? serviceName,
209231
TInput input,
@@ -236,6 +258,9 @@ ex is InvalidOperationException
236258
}
237259

238260
/// <inheritdoc/>
261+
#if NET6_0_OR_GREATER
262+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
263+
#endif
239264
public async Task<TOutput?> PostForAppAsync<TInput, TOutput>(
240265
string? serviceName,
241266
TInput input,
@@ -270,6 +295,9 @@ ex is InvalidOperationException
270295
}
271296

272297
/// <inheritdoc/>
298+
#if NET6_0_OR_GREATER
299+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
300+
#endif
273301
public async Task PutForUserAsync<TInput>(
274302
string? serviceName,
275303
TInput input,
@@ -303,6 +331,9 @@ ex is InvalidOperationException
303331
}
304332

305333
/// <inheritdoc/>
334+
#if NET6_0_OR_GREATER
335+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
336+
#endif
306337
public async Task<TOutput?> PutForUserAsync<TInput, TOutput>(
307338
string? serviceName,
308339
TInput input,
@@ -338,6 +369,9 @@ ex is InvalidOperationException
338369
}
339370

340371
/// <inheritdoc/>
372+
#if NET6_0_OR_GREATER
373+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
374+
#endif
341375
public async Task PutForAppAsync<TInput>(
342376
string? serviceName,
343377
TInput input,
@@ -370,6 +404,9 @@ ex is InvalidOperationException
370404
}
371405

372406
/// <inheritdoc/>
407+
#if NET6_0_OR_GREATER
408+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
409+
#endif
373410
public async Task<TOutput?> PutForAppAsync<TInput, TOutput>(
374411
string? serviceName,
375412
TInput input,
@@ -406,6 +443,9 @@ ex is InvalidOperationException
406443
#if !NETFRAMEWORK && !NETSTANDARD2_0
407444

408445
/// <inheritdoc/>
446+
#if NET6_0_OR_GREATER
447+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
448+
#endif
409449
public async Task PatchForUserAsync<TInput>(
410450
string? serviceName,
411451
TInput input,
@@ -439,6 +479,9 @@ ex is InvalidOperationException
439479
}
440480

441481
/// <inheritdoc/>
482+
#if NET6_0_OR_GREATER
483+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
484+
#endif
442485
public async Task<TOutput?> PatchForUserAsync<TInput, TOutput>(
443486
string? serviceName,
444487
TInput input,
@@ -474,6 +517,9 @@ ex is InvalidOperationException
474517
}
475518

476519
/// <inheritdoc/>
520+
#if NET6_0_OR_GREATER
521+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
522+
#endif
477523
public async Task PatchForAppAsync<TInput>(
478524
string? serviceName,
479525
TInput input,
@@ -506,6 +552,9 @@ ex is InvalidOperationException
506552
}
507553

508554
/// <inheritdoc/>
555+
#if NET6_0_OR_GREATER
556+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
557+
#endif
509558
public async Task<TOutput?> PatchForAppAsync<TInput, TOutput>(
510559
string? serviceName,
511560
TInput input,
@@ -542,6 +591,9 @@ ex is InvalidOperationException
542591
#endif // !NETFRAMEWORK && !NETSTANDARD2_0
543592

544593
/// <inheritdoc/>
594+
#if NET6_0_OR_GREATER
595+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
596+
#endif
545597
public async Task DeleteForUserAsync<TInput>(
546598
string? serviceName,
547599
TInput input,
@@ -575,6 +627,9 @@ ex is InvalidOperationException
575627
}
576628

577629
/// <inheritdoc/>
630+
#if NET6_0_OR_GREATER
631+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
632+
#endif
578633
public async Task<TOutput?> DeleteForUserAsync<TInput, TOutput>(
579634
string? serviceName,
580635
TInput input,
@@ -610,6 +665,9 @@ ex is InvalidOperationException
610665
}
611666

612667
/// <inheritdoc/>
668+
#if NET6_0_OR_GREATER
669+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
670+
#endif
613671
public async Task DeleteForAppAsync<TInput>(
614672
string? serviceName,
615673
TInput input,
@@ -642,6 +700,9 @@ ex is InvalidOperationException
642700
}
643701

644702
/// <inheritdoc/>
703+
#if NET6_0_OR_GREATER
704+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
705+
#endif
645706
public async Task<TOutput?> DeleteForAppAsync<TInput, TOutput>(
646707
string? serviceName,
647708
TInput input,

src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.HttpMethods.tt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Licensed under the MIT License.
99

1010
using System;
11+
using System.Diagnostics.CodeAnalysis;
1112
using System.Net.Http;
1213
using System.Security.Claims;
1314
using System.Threading;
@@ -55,6 +56,9 @@ namespace Microsoft.Identity.Web
5556
firstMethod = false;
5657
#>
5758
/// <inheritdoc/>
59+
#if NET6_0_OR_GREATER
60+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(response, effectiveOptions)")]
61+
#endif
5862
public async <#= returnType #> <#= httpMethod #>For<#= token #>Async<#= template #>(
5963
string? serviceName,
6064
<# if (hasInput){ #>

src/Microsoft.Identity.Web.DownstreamApi/DownstreamApi.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using System.Linq;
67
using System.Net.Http;
78
using System.Runtime.CompilerServices;
@@ -96,6 +97,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
9697
}
9798

9899
/// <inheritdoc/>
100+
#if NET6_0_OR_GREATER
101+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.SerializeInput<TInput>(TInput, DownstreamApiOptions)")]
102+
#endif
99103
public async Task<TOutput?> CallApiForUserAsync<TInput, TOutput>(
100104
string? serviceName,
101105
TInput input,
@@ -120,6 +124,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
120124

121125
/// <inheritdoc/>
122126
[MethodImpl(MethodImplOptions.AggressiveInlining)]
127+
#if NET6_0_OR_GREATER
128+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.SerializeInput<TInput>(TInput, DownstreamApiOptions)")]
129+
#endif
123130
public async Task<TOutput?> CallApiForAppAsync<TInput, TOutput>(
124131
string? serviceName,
125132
TInput input,
@@ -142,6 +149,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
142149

143150
/// <inheritdoc/>
144151
[MethodImpl(MethodImplOptions.AggressiveInlining)]
152+
#if NET6_0_OR_GREATER
153+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(HttpResponseMessage, DownstreamApiOptions)")]
154+
#endif
145155
public async Task<TOutput?> CallApiForAppAsync<TOutput>(string serviceName,
146156
Action<DownstreamApiOptions>? downstreamApiOptionsOverride = null,
147157
CancellationToken cancellationToken = default) where TOutput : class
@@ -154,6 +164,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
154164
}
155165

156166
/// <inheritdoc/>
167+
#if NET6_0_OR_GREATER
168+
[RequiresUnreferencedCode("Calls Microsoft.Identity.Web.DownstreamApi.DeserializeOutput<TOutput>(HttpResponseMessage, DownstreamApiOptions)")]
169+
#endif
157170
public async Task<TOutput?> CallApiForUserAsync<TOutput>(
158171
string? serviceName,
159172
Action<DownstreamApiOptions>? downstreamApiOptionsOverride = null,
@@ -217,6 +230,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
217230
return clonedOptions;
218231
}
219232

233+
#if NET6_0_OR_GREATER
234+
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Serialize<TValue>(TValue, JsonSerializerOptions)")]
235+
#endif
220236
private static HttpContent? SerializeInput<TInput>(TInput input, DownstreamApiOptions effectiveOptions)
221237
{
222238
HttpContent? effectiveInput;
@@ -238,6 +254,9 @@ public Task<HttpResponseMessage> CallApiForAppAsync(
238254
return effectiveInput;
239255
}
240256

257+
#if NET6_0_OR_GREATER
258+
[RequiresUnreferencedCode("Calls System.Text.Json.JsonSerializer.Deserialize<TValue>(String, JsonSerializerOptions)")]
259+
#endif
241260
private static async Task<TOutput?> DeserializeOutput<TOutput>(HttpResponseMessage response, DownstreamApiOptions effectiveOptions)
242261
where TOutput : class
243262
{

src/Microsoft.Identity.Web.DownstreamApi/DownstreamApiExtensions.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the MIT License.
33

44
using System;
5+
using System.Diagnostics.CodeAnalysis;
56
using Microsoft.Extensions.Configuration;
67
using Microsoft.Extensions.DependencyInjection;
78
using Microsoft.Identity.Abstractions;
@@ -21,6 +22,9 @@ public static class DownstreamApiExtensions
2122
/// This is the name used when calling the service from controller/pages.</param>
2223
/// <param name="configuration">Configuration.</param>
2324
/// <returns>The builder for chaining.</returns>
25+
#if NET6_0_OR_GREATER
26+
[RequiresUnreferencedCode("Microsoft.Extensions.DependencyInjection.OptionsConfigurationServiceCollectionExtensions.Configure<TOptions>(IServiceCollection, String, IConfiguration).")]
27+
#endif
2428
public static IServiceCollection AddDownstreamApi(
2529
this IServiceCollection services,
2630
string serviceName,
@@ -65,6 +69,9 @@ public static IServiceCollection AddDownstreamApi(
6569
/// This is the name used when calling the service from controller/pages.</param>
6670
/// <param name="configuration">Configuration.</param>
6771
/// <returns>The builder for chaining.</returns>
72+
#if NET6_0_OR_GREATER
73+
[RequiresUnreferencedCode("Microsoft.Identity.Web.DownstreamApiExtensions.AddDownstreamApi(IServiceCollection, String, IConfiguration).")]
74+
#endif
6875
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddDownstreamApi(
6976
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
7077
string serviceName,

src/Microsoft.Identity.Web.MicrosoftGraph/MicrosoftGraphExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Diagnostics.CodeAnalysis;
67
using System.Linq;
78
using Microsoft.Extensions.Configuration;
89
using Microsoft.Extensions.DependencyInjection;
@@ -24,6 +25,9 @@ public static class MicrosoftGraphExtensions
2425
/// <param name="builder">Builder.</param>
2526
/// <param name="configurationSection">Configuration section.</param>
2627
/// <returns>The builder to chain.</returns>
28+
#if NET6_0_OR_GREATER
29+
[RequiresUnreferencedCode("Microsoft.Extensions.Configuration.ConfigurationBinder.Bind(IConfiguration, Object).")]
30+
#endif
2731
public static MicrosoftIdentityAppCallsWebApiAuthenticationBuilder AddMicrosoftGraph(
2832
this MicrosoftIdentityAppCallsWebApiAuthenticationBuilder builder,
2933
IConfigurationSection configurationSection)

src/Microsoft.Identity.Web.TokenAcquisition/AspNetCore/ApplicationBuilderExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
using System.Diagnostics.CodeAnalysis;
45
using Microsoft.AspNetCore.Builder;
56

67
namespace Microsoft.Identity.Web
@@ -9,6 +10,9 @@ namespace Microsoft.Identity.Web
910
/// Extension class on IApplicationBuilder to initialize the service provider of
1011
/// the TokenAcquirerFactory in ASP.NET Core.
1112
/// </summary>
13+
#if NET6_0_OR_GREATER
14+
[RequiresUnreferencedCode("Microsoft.Identity.Web.TokenAcquirerFactory.GetDefaultInstance(String).")]
15+
#endif
1216
public static class ApplicationBuilderExtensions
1317
{
1418
/// <summary>

0 commit comments

Comments
 (0)