Skip to content

Commit

Permalink
Enable SingleFileAnalyzer (dotnet#47282)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
eerhardt authored Mar 20, 2023
1 parent 7b61996 commit 7a4829d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<Project>
<Project>
<PropertyGroup>
<EnableAOTAnalyzer Condition=" '$(EnableAOTAnalyzer)' == '' ">$([MSBuild]::ValueOrDefault($(IsTrimmable),'false'))</EnableAOTAnalyzer>
<!-- TODO: Remove when analyzer is enabled by default with AOT in SDK. See https://github.com/dotnet/sdk/issues/31284 -->
<EnableSingleFileAnalyzer Condition=" '$(EnableSingleFileAnalyzer)' == '' ">$(EnableAOTAnalyzer)</EnableSingleFileAnalyzer>
</PropertyGroup>

<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable enable

using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using Microsoft.AspNetCore.StaticWebAssets;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -63,6 +64,8 @@ internal static void UseStaticWebAssetsCore(IWebHostEnvironment environment, Str
}
}

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

0 comments on commit 7a4829d

Please sign in to comment.