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

[One .NET] set $(EnableSingleFileAnalyzer) by default #5989

Merged
merged 1 commit into from Jun 9, 2021

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Jun 3, 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

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
    ~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll
        IsImplicitlyDefined = true

Fixes: xamarin#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
Copy link
Member

jonpryor commented Jun 6, 2021

Pity I can't find any docs for $(EnableSingleFileAnalyzer)

@jonathanpeppers
Copy link
Member Author

Let's link to this PR as documentation? dotnet/sdk#15239

@jonpryor
Copy link
Member

jonpryor commented Jun 9, 2021

@jonpryor
Copy link
Member

jonpryor commented Jun 9, 2021

Fixes: https://github.com/xamarin/xamarin-android/issues/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: https://github.com/dotnet/sdk/pull/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

@jonathanpeppers
Copy link
Member Author

I had a typo in my original commit message:

--~\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll
++~\android-toolchain\dotnet\sdk\6.0.100-preview.6.21280.2\Sdks\Microsoft.NET.Sdk\targets\..\analyzers\ILLink.RoslynAnalyzer.dll

@jonpryor jonpryor merged commit d644609 into xamarin:main Jun 9, 2021
@jonathanpeppers jonathanpeppers deleted the enablesinglefileanalyzer branch June 9, 2021 16:32
@github-actions github-actions bot locked and limited conversation to collaborators Jan 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable analyzers for single-file like targets
2 participants