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

XA0106 warnings in Xamarin.Forms/Android project #1988

Closed
deakjahn opened this issue Jul 22, 2018 · 2 comments · Fixed by #3243
Closed

XA0106 warnings in Xamarin.Forms/Android project #1988

deakjahn opened this issue Jul 22, 2018 · 2 comments · Fixed by #3243

Comments

@deakjahn
Copy link

deakjahn commented Jul 22, 2018

Steps to Reproduce

  1. VS can be full of "Skipping .... Please check that your Nuget Package versions are compatible" warnings. This is supposed to be a XA0106 warning but it has no code, so it can't even be disabled in the project properties.
  2. The project compiles without any problems but the hundreds of warnings make an awful lot of unwanted noise.

I know it might come with specific Nuget Packages installed but there is no way to identify which. Disabling them should work, though.

Expected Behavior

A way to disable them.

Version Information

XF: 3.1.0.583944 (I know there is a newer one but it breaks important things so can't be installed. Anyway, this has no bearing on this particular issue).
XA support libraries: 27.0.2.1

@ArrowCase
Copy link

Please fix these warnings so they can be suppressed.

brendanzagaeski added a commit to brendanzagaeski/xamarin-android that referenced this issue Jun 19, 2019
Context: xamarin#1988

Also replace the `/nowarn` command line switch with its alias
`/warnasmessage` to help maintain a clear distcintion between this
command line switch and the *unrelated* `$(NoWarn)` MSBuild property.

I have verified that both the `/warnasmessage` command line switch and
the `$(MSBuildWarningsAsMessages)` MSBuild property successfully
suppress `XAnnnn` warnings such as `XA4214`.

The `/nowarn` command line switch for MSBuild does *not* correspond to
the `$(NoWarn)` MSBuild property.  In fact, the `$(NoWarn)` property is
not used at all by the MSBuild logger itself.  It is instead passed into
[the `<Csc/>` task in C# projects][0], [the `<Vbc/>` task in Visual
Basic projects][1], and [the `<PackTask/>` in the NuGet packaging
targets][2], which then *themselves* skip emitting the specified
warnings.

In the past, MSBuild did not provide a mechanism to filter warnings via
the MSBuild logger itself, so SDK targets had to implement the
functionality themsleves.  But then the `/nowarn` (aka `/warnasmessage`)
command line switch was added [a few years ago][3] to enable filtering
by the MSBuild logger.  The complication is that the meaning of the
`$(NoWarn)` property was already well established by then, so instead of
changing the semantics of that existing property, the team [added a
separate `$(MSBuildWarningsAsMessages)` property][4].

Another little complication is that the [MSBuild command-line
reference][5] does not yet mention the `/nowarn` or `/warnasmessage`
switch, and the [common MSBuild project properties documentation][6]
does not yet mention the `$(MSBuildWarningsAsMessages)` property.  Also,
there is not yet a GUI representation of this property in the Visual
Studio property pages.  (The **Build > Errors and warnings > Suppress
warnings** property pages setting corresponds to older the `$(NoWarn)`
property instead.)

[0]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L259
[1]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.VisualBasic.CurrentVersion.targets#L247
[2]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L246
[3]: dotnet/msbuild@4287837
[4]: dotnet/msbuild@01f9915
[5]: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019
[6]: https://docs.microsoft.com/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2019
brendanzagaeski added a commit to brendanzagaeski/xamarin-android that referenced this issue Jun 19, 2019
Context: xamarin#1988

Also replace the `/nowarn` command line switch with its alias
`/warnasmessage` to help maintain a clear distcintion between this
command line switch and the *unrelated* `$(NoWarn)` MSBuild property.

I have verified that both the `/warnasmessage` command line switch and
the `$(MSBuildWarningsAsMessages)` MSBuild property successfully
suppress `XAnnnn` warnings such as `XA4214`.

The `/nowarn` command line switch for MSBuild does *not* correspond to
the `$(NoWarn)` MSBuild property.  In fact, the `$(NoWarn)` property is
not used at all by the MSBuild logger itself.  It is instead passed into
[the `<Csc/>` task in C# projects][0], [the `<Vbc/>` task in Visual
Basic projects][1], and [the `<PackTask/>` in the NuGet packaging
targets][2], which then *themselves* skip emitting the specified
warnings.

In the past, MSBuild did not provide a mechanism to filter warnings via
the MSBuild logger itself, so SDK targets had to implement the
functionality themsleves.  But then the `/nowarn` (aka `/warnasmessage`)
command line switch was added [a few years ago][3] to enable filtering
by the MSBuild logger.  The complication is that the meaning of the
`$(NoWarn)` property was already well established by then, so instead of
changing the semantics of that existing property, the team [added a
separate `$(MSBuildWarningsAsMessages)` property][4].

Another little complication is that the [MSBuild command-line
reference][5] does not yet mention the `/nowarn` or `/warnasmessage`
switch, and the [common MSBuild project properties documentation][6]
does not yet mention the `$(MSBuildWarningsAsMessages)` property.  Also,
there is not yet a GUI representation of this property in the Visual
Studio property pages.  (The **Build > Errors and warnings > Suppress
warnings** property pages setting corresponds to older the `$(NoWarn)`
property instead.)

[0]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L259
[1]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.VisualBasic.CurrentVersion.targets#L247
[2]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L246
[3]: dotnet/msbuild@4287837
[4]: dotnet/msbuild@01f9915
[5]: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019
[6]: https://docs.microsoft.com/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2019
@brendanzagaeski
Copy link
Member

Thanks for this report, and apologies this issue didn't get a reply sooner!

By chance, these XA0106 warnings came up again in the context of the current Visual Studio 2019 version 16.2 Preview version, so I was looking into the story a bit more today. In short, I learned that there is already a way to suppress the warnings, but it isn't too well documented. To suppress the warnings, you can either:

  • Include XA0106 in the $(MSBuildWarningsAsMessages) property in your
    .csproj file:

    <PropertyGroup>
        <MSBuildWarningsAsMessages>XA0106</MSBuildWarningsAsMessages>
    </PropertyGroup>
  • Or add the -warnasmessage:XA0106 command line switch to the MSBuild invocation. This approach might be useful if you only need to suppress the warnings for command line builds on an automated build server, for example.

Additional background info

One of the tricky things about the $(MSBuildWarningsAsMessages) property and -warnasmessage command line switch is that that they were only added to MSBuild within the last few years (first the switch, and then property). They also aren't yet mentioned in the MSBuild documentation on docs.microsoft.com, and there isn't currently a way to edit $(MSBuildWarningsAsMessages) in the Visual Studio property pages UI.

Another reason these settings are tricky is that they are different from the $(NoWarn) MSBuild property. $(NoWarn) is an older property that corresponds to the Build > Errors and warnings > Suppress warnings setting in the Visual Studio property pages UI for C# projects. It is not used by the MSBuild logger directly. Instead, it gets passed into the C# compiler and NuGet restoration utility, allowing them to suppress warnings internally, before MSBuild sees them. Xamarin.Android could take a similar approach with the $(NoWarn) property to suppress warnings internally before MSBuild sees them, but it doesn't do that at the moment, and the $(MSBuildWarningsAsMessages) property now provides another solution.

One more potentially confusing detail to be aware of is that MSBuild offers 2 different names for the -warnasmessage command line switch. The second name is -nowarn, which sounds like it would match up with the older $(NoWarn) property, but they are actually unrelated. In fact, I just submitted #3251 to correct a few places in the xamarin-android warning message docs where the Xamarin.Android team, myself included, got fooled by the naming and incorrectly mentioned $(NoWarn) when we should have mentioned $(MSBuildWarningsAsMessages) instead.

brendanzagaeski added a commit to brendanzagaeski/xamarin-android that referenced this issue Jun 19, 2019
Context: xamarin#1988

Also replace the `/nowarn` command line switch with its alias
`/warnasmessage` to help emphasize the distinction between this command
line switch and the *unrelated* `$(NoWarn)` MSBuild property.

I have verified that both the `/warnasmessage` command line switch and
the `$(MSBuildWarningsAsMessages)` MSBuild property successfully
suppress `XAnnnn` warnings such as `XA4214`.

The reason behind these changes is that I learned that the `/nowarn`
command line switch for MSBuild does *not* correspond to the `$(NoWarn)`
MSBuild property.  In fact, the `$(NoWarn)` property is not used at all
by the MSBuild logger itself.  It is instead passed into the [`<Csc/>`
task in C# projects][0], the [`<Vbc/>` task in Visual Basic
projects][1], and the [`MSBuildRestoreUtility` class][2] and
[`<PackTask/>` task][3] in the NuGet package manager, allowing those
tools to suppress the warnings internally, before MSBuild sees them.

In the past, MSBuild did not provide a mechanism to suppress warnings
via the MSBuild logger itself, so Xamarin.Android would have had to
provide its own mechanism to suppress warnings internally.  But as of [a
few years ago][4], MSBuild now includes a `/nowarn` (aka
`/warnasmessage`) command line switch to control how the MSBuild logger
itself suppresses warnings.  The complication is that the meaning of the
`$(NoWarn)` property was already well established by then, so instead of
changing the semantics of that existing property, the team [added a
separate `$(MSBuildWarningsAsMessages)` property][5] to go along with
the new command line switch.

Another little complication is that the [MSBuild command-line
reference][6] does not yet mention the `/nowarn` or `/warnasmessage`
switch, and the [common MSBuild project properties documentation][7]
does not yet mention the `$(MSBuildWarningsAsMessages)` property.  The
Visual Studio property pages UI doesn't currently include this property
either.  (The [**Build > Errors and warnings > Suppress warnings**][8]
Visual Studio property pages setting corresponds to older the
`$(NoWarn)` property instead.)

[0]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L259
[1]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.VisualBasic.CurrentVersion.targets#L247
[2]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs#L606
[3]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L246
[4]: dotnet/msbuild@4287837
[5]: dotnet/msbuild@01f9915
[6]: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019
[7]: https://docs.microsoft.com/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2019
[8]: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-suppress-compiler-warnings?view=vs-2019#suppress-specific-warnings-for-visual-c-or-f
jonpryor pushed a commit that referenced this issue Jun 19, 2019
Context: #1988

Replace the `msbuild /nowarn` command line switch with its alias
`msbuild /warnasmessage` to help emphasize the distinction between
this command line switch and the *unrelated* `$(NoWarn)` MSBuild
property.

I have verified that both the `/warnasmessage` command line switch
and the `$(MSBuildWarningsAsMessages)` MSBuild property successfully
suppress `XAnnnn` warnings such as `XA4214`.

The reason behind these changes is that I learned that the
`msbuild /nowarn` option does *not* correspond to the `$(NoWarn)`
MSBuild property.  In fact, the `$(NoWarn)` property is not used at
allby the MSBuild logger itself.  It is instead passed into the
[`<Csc/>` task in C# projects][0], the
[`<Vbc/>` task in Visual Basic projects][1], and the
[`MSBuildRestoreUtility` class][2] and [`<PackTask/>` task][3] in the
NuGet package manager, allowing those tools to suppress the warnings
internally, before MSBuild sees them.

In the past, MSBuild did not provide a mechanism to suppress warnings
via the MSBuild logger itself, so Xamarin.Android would have had to
provide its own mechanism to suppress warnings internally.  But as of
[a few years ago][4], MSBuild now includes an `msbuild /nowarn` (aka
`msbuild /warnasmessage`) option to control how the MSBuild logger
itself suppresses warnings.  The complication is that the meaning of
the `$(NoWarn)` property was already well established by then, so
instead of changing the semantics of that existing property, they
[added a separate `$(MSBuildWarningsAsMessages)` property][5] to go
along with the new command line option.

Another little complication is that the
[MSBuild command-line reference][6] does not yet mention the
`msbuild /nowarn` or `msbuild /warnasmessage` options, and the
[common MSBuild project properties documentation][7] does not yet
mention the `$(MSBuildWarningsAsMessages)` property.
The Visual Studio property pages UI doesn't currently include this
property either.

(The [**Build > Errors and warnings > Suppress warnings**][8] Visual
Studio property pages setting corresponds to older the `$(NoWarn)`
property instead.)

Update the documentation to reference `msbuild /warnasmessage` and
the `$(MSBuildWarningsAsMessages)` properties, instead of the
(confusing) `msbuild /nowarn` option and (incorrect) `$(NoWarn)` prop.

[0]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.CSharp.CurrentVersion.targets#L259
[1]: https://github.com/microsoft/msbuild/blob/v16.0.461.62831/src/Tasks/Microsoft.VisualBasic.CurrentVersion.targets#L247
[2]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Commands/RestoreCommand/Utility/MSBuildRestoreUtility.cs#L606
[3]: https://github.com/NuGet/NuGet.Client/blob/5.2.0.6045/src/NuGet.Core/NuGet.Build.Tasks.Pack/NuGet.Build.Tasks.Pack.targets#L246
[4]: dotnet/msbuild@4287837
[5]: dotnet/msbuild@01f9915
[6]: https://docs.microsoft.com/visualstudio/msbuild/msbuild-command-line-reference?view=vs-2019
[7]: https://docs.microsoft.com/visualstudio/msbuild/common-msbuild-project-properties?view=vs-2019
[8]: https://docs.microsoft.com/en-us/visualstudio/ide/how-to-suppress-compiler-warnings?view=vs-2019#suppress-specific-warnings-for-visual-c-or-f
@ghost ghost locked as resolved and limited conversation to collaborators Jun 7, 2022
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 a pull request may close this issue.

3 participants