tmaj
tmaj

Reputation: 34967

Suppress a single compiler error (e.g. NU1603)

Is it possible to suppress a single instance of a NuGet error?

I'm getting the NU1603 below, I believe I cannot fix this and I don't want to suppress all 1603 for the whole project.

NU1603: runtime.native.System.IO.Compression 4.3.0 depends on runtime.win10-arm64.runtime.native.System.IO.Compression (>= 4.3.0) but runtime.win10-arm64.runtime.native.System.IO.Compression 4.3.0 was not found. An approximate best match of runtime.win10-arm64.runtime.native.System.IO.Compression 4.3.1 was resolved. NuGet package restore failed. Please see Error List window for detailed warnings and errors.

Update

Steps to reproduce the warning are:

  1. Create a new Win IoT Core Background App targeting 16299.
  2. Add a NuGet reference to Microsoft.Azure.Devices.Provisioning.Transport.Mqtt v1.1.1 (via Tools -> NuGet Package Manager -> Manage NuGet Packages For Solution...)
  3. Build

Extra steps to try remediate

Add a NuGet reference to System.IO.Compression 4.3.0 (latest)

The project file now contains

<PackageReference Include="System.IO.Compression"> <Version>4.3.0</Version> </PackageReference>

Add <NoWarn>

<PackageReference Include="System.IO.Compression"> <Version>4.3.0</Version> <NoWarn>NU1603</NoWarn> </PackageReference>

The warning is still there. Now,


Update 2 27/06/2018

Here is the project file:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">x86</Platform>
    <ProjectGuid>{1053DA3E-BC0F-47EA-946C-24EA813DB098}</ProjectGuid>
    <OutputType>winmdobj</OutputType>
    <AppDesignerFolder>Properties</AppDesignerFolder>
    <RootNamespace>BackgroundApplication1</RootNamespace>
    <AssemblyName>BackgroundApplication1</AssemblyName>
    <DefaultLanguage>en-US</DefaultLanguage>
    <TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
    <TargetPlatformVersion>10.0.16299.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.16299.0</TargetPlatformMinVersion>
    <MinimumVisualStudioVersion>14</MinimumVisualStudioVersion>
    <EnableDotNetNativeCompatibleProfile>true</EnableDotNetNativeCompatibleProfile>
    <FileAlignment>512</FileAlignment>
    <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
    <AllowCrossPlatformRetargeting>false</AllowCrossPlatformRetargeting>
    <PackageCertificateKeyFile>BackgroundApplication1_TemporaryKey.pfx</PackageCertificateKeyFile>
    <AppxPackage>true</AppxPackage>
    <ContainsStartupTask>true</ContainsStartupTask>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|ARM'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\ARM\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <NoWarn>;2008</NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>ARM</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|ARM'">
    <OutputPath>bin\ARM\Release\</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>ARM</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x64\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <NoWarn>;2008</NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    <OutputPath>bin\x64\Release\</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x64</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    <DebugSymbols>true</DebugSymbols>
    <OutputPath>bin\x86\Debug\</OutputPath>
    <DefineConstants>DEBUG;TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <NoWarn>;2008</NoWarn>
    <DebugType>full</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
  </PropertyGroup>
  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    <OutputPath>bin\x86\Release\</OutputPath>
    <DefineConstants>TRACE;NETFX_CORE;WINDOWS_UWP</DefineConstants>
    <Optimize>true</Optimize>
    <NoWarn>;2008</NoWarn>
    <DebugType>pdbonly</DebugType>
    <PlatformTarget>x86</PlatformTarget>
    <UseVSHostingProcess>false</UseVSHostingProcess>
    <ErrorReport>prompt</ErrorReport>
    <Prefer32Bit>true</Prefer32Bit>
    <UseDotNetNativeToolchain>true</UseDotNetNativeToolchain>
  </PropertyGroup>
  <PropertyGroup>
    <RestoreProjectStyle>PackageReference</RestoreProjectStyle>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="StartupTask.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <ItemGroup>
    <AppxManifest Include="Package.appxmanifest">
      <SubType>Designer</SubType>
    </AppxManifest>
    <None Include="BackgroundApplication1_TemporaryKey.pfx" />
  </ItemGroup>
  <ItemGroup>
    <Content Include="Properties\Default.rd.xml" />
    <Content Include="Assets\LockScreenLogo.scale-200.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\SplashScreen.scale-200.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\Square150x150Logo.scale-200.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\Square44x44Logo.scale-200.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\StoreLogo.png">
      <InProject>false</InProject>
    </Content>
    <Content Include="Assets\Wide310x150Logo.scale-200.png">
      <InProject>false</InProject>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.Azure.Devices.Provisioning.Transport.Mqtt">
      <Version>1.1.1</Version>
      <NoWarn>NU1603</NoWarn>
    </PackageReference>
    <PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform">
        <NoWarn>NU1603</NoWarn>
      <Version>6.1.5</Version>
    </PackageReference>
    <PackageReference Include="System.IO.Compression">
      <Version>4.3.0</Version>
      <NoWarn>NU1603</NoWarn>
    </PackageReference>
  </ItemGroup>
  <PropertyGroup Condition=" '$(VisualStudioVersion)' == '' or '$(VisualStudioVersion)' &lt; '15.0' ">
    <VisualStudioVersion>15.0</VisualStudioVersion>
  </PropertyGroup>
  <Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />
  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
       Other similar extension points exist, see Microsoft.Common.targets.
  <Target Name="BeforeBuild">
  </Target>
  <Target Name="AfterBuild">
  </Target>
  -->
</Project>

Upvotes: 7

Views: 11561

Answers (2)

Mike Nakis
Mike Nakis

Reputation: 61969

First of all, let's set a few things straight:

1. This is not a compiler error. Compiler errors are not issued under these circumstances, and they do not begin with "NU".

2. It is not even an error. If it was, then it would not make any sense to be asking how to suppress it, because it is in the definition of an error that it is something that must be dealt with and fixed, you cannot just ignore it.

So: NU1603 is a warning, not an error, and it is issued by NuGet, not the compiler.

And now on with the question...


This is a very well known problem with NuGet.

Nuget will indeed, entirely erroneously, issue warning NU1603, under entirely normal circumstances.

This has been brought to the attention of the creators of NuGet via a bug report, (See NuGet issue 5764 on Github) but they appear to be under the impression that the warning is fine as it is, so they have dismissed the bug report as being like that "by design".

A workaround to this problem was given by "Leo Liu-MSFT" in a comment to another answer to this question, but it deserves to be an answer by itself, so here it is:

The workaround is to suppress this specific warning when referencing a package, on a package-per-package basis.

In your project file (which is of course PackageReference-style instead of packages.config style, right?) you have entries like this:

<PackageReference Include="acme.AcmePackage">
  <Version>4.7.0</Version>
</PackageReference>

Replace them with the following:

<PackageReference Include="acme.AcmePackage">
   <Version>4.7.0</Version>
   <NoWarn>NU1603</NoWarn>   
</PackageReference>

FURTHERMORE

You may receive NU1603 on a package that your solution does not even reference!

This can happen for example if your solution depends on packages A and B, and each one of them depends on a different version of yet a third package C. In this case, NuGet will issue this warning for package C.

The workaround to this problem is to explicitly reference package C from within each one of your projects that depends on either A or B, even though those projects do not depend on C, just so that you can suppress NU1603 for C.


AS A MATTER OF FACT

This problem can even occur with 3 or more levels of indirection, meaning that you may encounter this problem even in situations where none of the projects in your solution reference any of the packages A, B, or C.

When this happens, finding which projects indirectly reference C might seem like a daunting task, at which point most folks probably just resign to having warning NU1603 in their face each time they build, because it is just too much hassle to eradicate the darn thing.

It is, however, possible to do it. You need to invoke this command in your solution folder:

nuget restore -Verbosity detailed -DisableParallelProcessing 

This will do two things for you:

  • Turn on detailed verbosity so that you can see during the processing of which project warning NU1603 was issued.
  • Disable parallel processing so that the diagnostic messages issued by NuGet for each project do not get mixed.

So, by knowing which projects cause NU1603 to be issued, you can add the necessary package references and warning suppressions to these projects, as explained above.

Upvotes: 8

Leo Liu
Leo Liu

Reputation: 76700

Is it possible to suppress a single instance of a NuGet error?

To accomplish this, you can try to suppress this NuGet compiler warnings for a single NuGet package runtime.native.System.IO.Compression 4.3.0, instead of for an entire project.

To suppress a specific warning for a single NuGet package:

  1. In Solution Explorer, select the NuGet package you want to suppress compiler warnings for.
  2. From the right-click or context menu, select Properties.
  3. In the NoWarn box of the package's properties, enter the warning number you want to suppress for this package. If you want to suppress more than one warning, use a comma to separate the warning numbers.

Check the details: Suppress warnings for NuGet packages

In some cases, you may want to suppress NuGet compiler warnings for a single NuGet package, instead of for an entire project. The warning serves a purpose, so you don't want to suppress it at the project level. For example, one of the NuGet warnings tells you that the package may not be fully compatible with your project. If you suppress it at the project level and later add an additional NuGet package, you would never know if it was producing the compatibility warning.

Hope this helps.

Upvotes: 4

Related Questions