tym*_*tam 6 msbuild visual-studio nuget
是否可以抑制 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.
更新
重现该警告的步骤是:
Microsoft.Azure.Devices.Provisioning.Transport.Mqtt v1.1.1
(通过工具->NuGet 包管理器->管理解决方案的 NuGet 包...)尝试修复的额外步骤
添加对 System.IO.Compression 4.3.0(最新)的 NuGet 引用
项目文件现在包含
<PackageReference Include="System.IO.Compression">
<Version>4.3.0</Version>
</PackageReference>
添加<NoWarn>
<PackageReference Include="System.IO.Compression">
<Version>4.3.0</Version>
<NoWarn>NU1603</NoWarn>
</PackageReference>
警告仍然存在。现在,
更新 2 2018 年 6 月 27 日
这是项目文件:
<?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)' < '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>
Run Code Online (Sandbox Code Playgroud)
首先,让我们明确一些事情:
1. 这不是编译器错误。在这些情况下不会发出编译器错误,并且它们不以“NU”开头。
2. 这甚至不是一个错误。如果是,那么询问如何抑制它就没有任何意义,因为在错误的定义中,它是必须处理和修复的东西,你不能忽略它。
因此:NU1603 是一个警告,而不是错误,它是由 NuGet 发出的,而不是编译器发出的。
现在问这个问题...
这是 NuGet 中一个众所周知的问题。
在完全正常的情况下,Nuget 确实会完全错误地发出警告 NU1603。
这已通过错误报告引起了 NuGet 创建者的注意(请参阅Github 上的 NuGet 问题 5764),但他们似乎认为该警告本身就很好,因此他们忽略了该错误报告“设计使然”就是这样。
“Leo Liu-MSFT”在对此问题的另一个答案的评论中给出了此问题的解决方法,但它本身值得成为一个答案,所以这里是:
解决方法是在引用包时,逐个包地抑制此特定警告。
在您的项目文件(当然是 PackageReference 样式而不是 packages.config 样式,对吧?)中,您有如下条目:
<PackageReference Include="acme.AcmePackage">
<Version>4.7.0</Version>
</PackageReference>
Run Code Online (Sandbox Code Playgroud)
将它们替换为以下内容:
<PackageReference Include="acme.AcmePackage">
<Version>4.7.0</Version>
<NoWarn>NU1603</NoWarn>
</PackageReference>
Run Code Online (Sandbox Code Playgroud)
此外
您可能会在一个包装中收到 NU1603,而您的解决方案甚至没有引用该包装!
例如,如果您的解决方案依赖于包 A 和 B,并且每个解决方案都依赖于第三个包 C 的不同版本,则可能会发生这种情况。在这种情况下,NuGet 将为包 C 发出此警告。
此问题的解决方法是从依赖于 A 或 B 的每个项目中显式引用包 C,即使这些项目不依赖于 C,这样您就可以抑制 C 的 NU1603。
事实上
此问题甚至可能在 3 个或更多间接级别上发生,这意味着即使解决方案中没有任何项目引用任何包 A、B 或 C,您也可能会遇到此问题。
当这种情况发生时,找到哪些项目间接引用了 C 似乎是一项艰巨的任务,此时大多数人可能只能接受每次构建时都会出现的警告 NU1603,因为根除这个该死的东西太麻烦了。
然而,这是可能做到的。您需要在解决方案文件夹中调用此命令:
nuget restore -Verbosity detailed -DisableParallelProcessing
Run Code Online (Sandbox Code Playgroud)
这将为您做两件事:
因此,通过了解哪些项目导致发布 NU1603,您可以向这些项目添加必要的包引用和警告抑制,如上所述。
是否可以抑制 NuGet 错误的单个实例?
为此,您可以尝试抑制单个 NuGet 包(runtime.native.System.IO.Compression 4.3.0而不是整个项目)的 NuGet 编译器警告。
要抑制单个 NuGet 包的特定警告:
检查详细信息:抑制 NuGet 包的警告
在某些情况下,您可能希望抑制单个 NuGet 包(而不是整个项目)的 NuGet 编译器警告。该警告是有目的的,因此您不想在项目级别抑制它。例如,NuGet 警告之一告诉您该包可能与您的项目不完全兼容。如果您在项目级别抑制它,然后添加额外的 NuGet 包,您将永远不知道它是否会产生兼容性警告。
希望这可以帮助。
| 归档时间: |
|
| 查看次数: |
9462 次 |
| 最近记录: |