Skip to content
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

Enable SingleFileAnalyzer #47282

Merged
merged 2 commits into from
Mar 20, 2023
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
Next Next commit
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 committed Mar 17, 2023
commit f38230fdf0f6ece069499953e924583aca3e64c0
3 changes: 2 additions & 1 deletion Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<Project>
<Project>
<PropertyGroup>
<EnableAOTAnalyzer Condition=" '$(EnableAOTAnalyzer)' == '' ">$([MSBuild]::ValueOrDefault($(IsTrimmable),'false'))</EnableAOTAnalyzer>
<EnableSingleFileAnalyzer Condition=" '$(EnableSingleFileAnalyzer)' == '' ">$(EnableAOTAnalyzer)</EnableSingleFileAnalyzer>
eerhardt marked this conversation as resolved.
Show resolved Hide resolved
</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