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 analyzers for single-file like targets #5943

Closed
marek-safar opened this issue May 20, 2021 · 0 comments · Fixed by #5989
Closed

Enable analyzers for single-file like targets #5943

marek-safar opened this issue May 20, 2021 · 0 comments · Fixed by #5989
Assignees
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Milestone

Comments

@marek-safar
Copy link
Contributor

.NET6 comes with a new set of analyzers that will issue warnings and offer code fixes for APIs calls that are not supported for single-file setups.

What is needed on the SDK side is to enable EnableSingleFileAnalyzer msbuild property. It would be useful to have this enabled for all android targets but also for the SDK build as well.

@marek-safar marek-safar added the needs-triage Issues that need to be assigned. label May 20, 2021
@jpobst jpobst assigned jonathanpeppers and unassigned jpobst May 20, 2021
@jpobst jpobst added Area: App+Library Build Issues when building Library projects or Application projects. and removed needs-triage Issues that need to be assigned. labels May 20, 2021
@jpobst jpobst added this to the One .NET milestone May 20, 2021
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this issue Jun 3, 2021
Fixes: dotnet#5943
Context: https://github.com/dotnet/sdk/blob/c1b8e80be1f7cca767ed9f3c90a45d6830b166a0/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L92-L96

By default, we need to enable ILLink's "single file" analyzers for
Android app projects. We should also do this for `Mono.Android.csproj`
and `Mono.Android.Export.csproj`.

After enabling this analyzer, no warnings appeared. But I do see the
appropriate analyzers setup in projects now:

    Analyzer
        ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.CodeFixProvider.dll
            IsImplicitlyDefined = true
        ~\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll
            IsImplicitlyDefined = true
jonpryor pushed a commit that referenced this issue Jun 9, 2021
Fixes: #5943

Context: https://github.com/dotnet/sdk/blob/c1b8e80be1f7cca767ed9f3c90a45d6830b166a0/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.Analyzers.targets#L92-L96
Context: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file
Context: dotnet/sdk#15239

[.NET Single File Apps][0] are a .NET deployment construct in which
"all application-dependent files [are built] into a single binary."
It's conceptually similar to Xamarin.Android `.apk` files, and there
is some overlap in the "semantic [API incompatibilities][1]" between
"normal" desktop .NET apps and Xamarin.Android/single-file apps,
such as the (lack of) utility in `Assembly.Location`, which is the
empty string in Xamarin.Android apps when
`$(EmbedAssembliesIntoApk)`=True, which is required for "app store"
distribution.

For .NET 6+ app builds, enable analyzers which check for usage of
these "semantically changed" APIs, by setting
`$(EnableSingleFileAnalyzer)`=True.

Update `Mono.Android.csproj` and `Mono.Android.Export.csproj` to also
enable the single-file analyzers.

After enabling this analyzer, no warnings appeared. But I do see the
appropriate analyzers setup in projects now:

	Analyzer
	    ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.CodeFixProvider.dll
	        IsImplicitlyDefined = true
	    ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll
	        IsImplicitlyDefined = true

[0]: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file
[1]: https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file#api-incompatibility
@ghost ghost locked as resolved and limited conversation to collaborators Jun 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Area: App+Library Build Issues when building Library projects or Application projects.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants