Skip to content

Commit 7a4829d

Browse files
authored
Enable SingleFileAnalyzer (dotnet#47282)
* Enable SingleFileAnalyzer When publishing an app that uses WebApplication.CreateBuilder, we are getting unnecessary warnings. We need the single file analyzer enabled in our code that is trimmable/AOT-able. When publishing for NativeAOT, the app is built into a single file, so we also need to ensure our code works correctly in single file mode.
1 parent 7b61996 commit 7a4829d

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

Directory.Build.targets

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
<Project>
1+
<Project>
22
<PropertyGroup>
33
<EnableAOTAnalyzer Condition=" '$(EnableAOTAnalyzer)' == '' ">$([MSBuild]::ValueOrDefault($(IsTrimmable),'false'))</EnableAOTAnalyzer>
4+
<!-- TODO: Remove when analyzer is enabled by default with AOT in SDK. See https://github.com/dotnet/sdk/issues/31284 -->
5+
<EnableSingleFileAnalyzer Condition=" '$(EnableSingleFileAnalyzer)' == '' ">$(EnableAOTAnalyzer)</EnableSingleFileAnalyzer>
46
</PropertyGroup>
57

68
<PropertyGroup>

src/Hosting/Hosting/src/StaticWebAssets/StaticWebAssetsLoader.cs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#nullable enable
55

6+
using System.Diagnostics.CodeAnalysis;
67
using System.Reflection;
78
using Microsoft.AspNetCore.StaticWebAssets;
89
using Microsoft.Extensions.Configuration;
@@ -63,6 +64,8 @@ internal static void UseStaticWebAssetsCore(IWebHostEnvironment environment, Str
6364
}
6465
}
6566

67+
[UnconditionalSuppressMessage("SingleFile", "IL3000:Assembly.Location",
68+
Justification = "The code handles if the Assembly.Location is empty by calling AppContext.BaseDirectory. Workaround https://github.com/dotnet/runtime/issues/83607")]
6669
private static string? ResolveRelativeToAssembly(IWebHostEnvironment environment)
6770
{
6871
if (string.IsNullOrEmpty(environment.ApplicationName))

0 commit comments

Comments
 (0)