【问题标题】:Suppress a single compiler error (e.g. NU1603)抑制单个编译器错误(例如 NU1603)
【发布时间】:2018-11-26 21:25:05
【问题描述】:

是否可以抑制 NuGet 错误的单个实例?

我得到了下面的 NU1603,我相信我无法解决这个问题,我不想在整个项目中抑制所有 1603。

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.

更新

重现警告的步骤是:

  1. 创建一个针对 16299 的新 Win IoT Core 后台应用程序。
  2. 添加对Microsoft.Azure.Devices.Provisioning.Transport.Mqtt v1.1.1 的 NuGet 引用 (通过工具 -> NuGet 包管理器 -> 管理 NuGet 包以获取解决方案...)
  3. 构建

尝试修复的额外步骤

添加对 System.IO.Compression 4.3.0(最新)的 NuGet 引用

项目文件现在包含

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

添加&lt;NoWarn&gt;

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

警告仍然存在。 现在,


更新 2 27/06/2018

这是项目文件:

<?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>

【问题讨论】:

    标签: visual-studio msbuild nuget


    【解决方案1】:

    是否可以抑制 NuGet 错误的单个实例?

    要实现此目的,您可以尝试针对单个 NuGet 包 runtime.native.System.IO.Compression 4.3.0 而不是整个项目抑制此 NuGet 编译器警告。

    取消针对单个 NuGet 包的特定警告:

    1. 在解决方案资源管理器中,选择要禁止显示的 NuGet 包 编译器警告。
    2. 从右键单击或上下文菜单中,选择属性。
    3. 在包属性的 NoWarn 框中,输入警告 您要为此包禁止显示的数字。如果你想 抑制多个警告,使用逗号分隔警告 数字。

    查看详情:Suppress warnings for NuGet packages

    在某些情况下,您可能希望禁止针对单个 NuGet 包而不是整个项目的 NuGet 编译器警告。该警告是有目的的,因此您不想在项目级别禁止它。例如,NuGet 警告之一告诉您该包可能与您的项目不完全兼容。如果您在项目级别禁止它,然后添加一个额外的 NuGet 包,您将永远不会知道它是否会产生兼容性警告。

    希望这会有所帮助。

    【讨论】:

    • 唯一的问题是我看不到任何属性。对于所有 NuGet 包,它们都是空的。
    • 你的包管理器类型是什么?是 packages.config 还是 Packagereference?如果是 packagereference,请尝试使用这个:&lt;PackageReference Include="runtime.native.System.IO.Compression" Version="4.3.0"&gt; &lt;NoWarn&gt;NU1603&lt;/NoWarn&gt; &lt;/PackageReference&gt;。如果没有帮助,请向我们提供更多详细信息、重现此问题的一些步骤或有关它的一些屏幕截图。
    • 我添加了一个基本的测试用例。
    • @tymtam,谢谢您的回复。我用你的步骤创建了一个示例,但无法重现警告,项目构建成功,没有任何警告,错误消息是关于包 runtime.native.System.IO.Compression Not System.IO.Compression,所以我认为是 NU1603不是来自System.IO.Compression,可能来自runtime.native.System.IO.Compression。如果您不介意,请在您的问题中分享您的 .csproj 文件,以便我检查警告的来源。
    • @tymtam,再次,根据错误信息,更新包runtime.win10-arm64.runtime.native.System.IO.Compression到4.3.0怎么样?
    【解决方案2】:

    这是 NuGet 的一个众所周知的问题。

    在完全正常的情况下,Nuget 确实会完全错误地发出警告 NU1603。

    这已通过错误报告引起 NuGet 的创建者的注意,

    (见https://github.com/NuGet/Home/issues/5764

    但他们似乎认为警告没有问题,因此他们认为错误报告是“设计使然”。

    “Leo Liu-MSFT”在对这个问题的另一个答案的评论中给出了解决这个问题的方法,但它本身就应该成为一个答案,所以这里是:

    解决方法是在引用包时按每个包禁止此特定警告。

    在您的项目文件中(当然是 PackageReference 样式而不是 packages.config 样式,对吗?)您有这样的条目:

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

    将它们替换为以下内容:

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

    更多

    您可能会收到您的解决方案甚至没有引用的包裹上的 NU1603!

    例如,如果您的解决方案依赖于包 A 和 B,并且它们中的每一个都依赖于第三个包 C 的不同版本,则可能会发生这种情况。在这种情况下,NuGet 将为包 C 发出此警告。

    解决此问题的方法是从依赖于 A 或 B 的每个项目中显式引用包 C,即使这些项目不依赖于 C,也可以为 C 抑制 NU1603。

    事实上,这个问题甚至可能出现在 3 级或更多级别的间接中,这意味着您可能会在没有项目的情况下遇到此问题在您的解决方案中引用任何包 A、B 或 C。发生这种情况时,查找哪些项目间接引用 C 似乎是一项艰巨的任务,此时大多数人可能只是辞职,每次他们都面对警告 NU1603构建,因为根除该死的东西太麻烦了。

    但是,可以这样做。您需要在解决方案文件夹中调用此命令:

    nuget restore -Verbosity detailed -DisableParallelProcessing 
    

    这将为您做两件事:

    • 打开详细的详细信息,以便您可以看到在处理过程中发出了哪个项目警告 NU1603。
    • 禁用并行处理,以免 NuGet 为每个项目发出的诊断消息混在一起。

    因此,通过了解哪些项目导致发布 NU1603,您可以向这些项目添加必要的包引用和警告抑制,如上所述。

    【讨论】:

      猜你喜欢
      • 2018-03-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多