創建 NuGet 包:NU5128 異常 - 不清楚如何修復
我有一個針對 .NET 4.7.1 庫的 DLL。
可能無關緊要,但它是用 C# 編寫的,並使用“packages.config”模式而不是較新的 PackageReference 配置來使用 NuGet 包。
我將它作為 NuGet 包發布(已經這樣做了好幾年了)。但是現在當我執行以下操作時:
nuget pack -Properties Configuration=Release我收到以下警告:
錯誤 NU5128:在 nuspec 的依賴項組和 lib/ref 文件夾中聲明的某些目標框架在其他位置沒有完全匹配。請參閱以下操作列表: - 將 .NETFramework4.7.1 的依賴組添加到 nuspec
我在 nuspec 的依賴項組中沒有任何內容:
<?xml version="1.0"?> <package > <metadata> <id>*******</id> <version>*******</version> <title>*******</title> <authors>*******</authors> <owners>*******</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>*******</description> <releaseNotes>*******</releaseNotes> <copyright>*******</copyright> <tags>*******</tags> </metadata> </package>這會使用以下 NuGet 包:
- Microsoft.AspNet.WebApi.Client v5.2.7
- Microsoft.AspNet.WebApi.Core v5.2.7
- Microsoft.CodeAnalysis.FxCopAnalyzers v2.9.8
- Microsoft.CodeAnalysis.VersionCheckAnalyzer v2.9.8
- Microsoft.CodeQuality.Analyzers v2.9.8
- Microsoft.NetCore.Analyzers v2.9.8
- Microsoft.NetFramework.Analyzers v2.9.8
- Newtonsoft.Json v12.0.3
- StyleCop.Analyzers v1.1.118
當我查看參考資料時,我看到以下內容(使用 ~ 來縮短路徑):
- Microsoft.CSharp ~ .NETFramework\v4.7.1\Microsoft.CSharp.dll
- Newtonsoft.Json ~\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll
- 系統~\NETFramework\v4.7.1\System.dll
- System.Configuration ~.NETFramework\v4.7.1\System.Configuration.dll
- System.Core ~.NETFramework\v4.7.1\System.Core.dll
- System.Data ~ .NETFramework\v4.7.1\System.Data.dll
- System.Data.DataSetExtensions ~.NETFramework\v4.7.1\System.Data.DataSetExtensions.dll
- System.Net.Http ~.NETFramework\v4.7.1\System.Net.Http.dll
- System.Net.Http.Formatting ~\packages\Microsoft.AspNet.WebApi.Client.5.2.7\lib\net45\System.Net.Http.Formatting.dll
- System.Web.Http ~\packages\Microsoft.AspNet.WebApi.Core.5.2.7\lib\net45\System.Web.Http.dll
- System.Xml ~.NETFramework\v4.7.1\System.Xml.dll
- System.Xml.Linq ~ .NETFramework\v4.7.1\System.Xml.Linq.dll
所以在我看來,一切看起來都與 .NET 4.7.1 兼容,那麼為什麼會出現這個警告呢?
按照NuGet 警告 NU5128中給出的詳細資訊,我因此添加了一個依賴組:
<?xml version="1.0"?> <package > <metadata> <id>*******</id> <version>*******</version> <title>*******</title> <authors>*******</authors> <owners>*******</owners> <requireLicenseAcceptance>false</requireLicenseAcceptance> <description>*******</description> <releaseNotes>*******</releaseNotes> <copyright>*******</copyright> <tags>*******</tags> <dependencies> <group targetFramework=".NETFramework4.7.1" /> </dependencies> </metadata> </package>但這沒有效果,我仍然得到錯誤。
根據NU5128文件,此警告是在 NuGet 5.3 的開發過程中添加的,並且首先在 .NET Core SDK 3.0 預覽版 9 中可用。NuGet/Home#8583跟踪在太多場景中引發警告的問題。您可以使用 NoWarn MSBuild 屬性(將 $(NoWarn);NU5128 添加到項目文件中的任何 PropertyGroup)。如果您有多個項目受到影響,您可以使用Directory.Build.targets自動將 NoWarn 添加到所有項目
從 Nuget 5.7 開始,這現在報告為來自 Nuget CLI ( https://github.com/NuGet/Home/issues/7404 ) 的錯誤 - 因此,即使我們之前遇到過此錯誤,我們的管道也開始失敗。
如上所述,我們最終在相關 csproj 文件中採用了 Nowarn 方法 - 但我想補充一點,這可能會突然導致已經執行的管道出現問題。
