gpt4 book ai didi

.net - NuGet 锁定文件无法使用 --locked-mode 还原

转载 作者:行者123 更新时间:2023-12-04 11:19:48 41 4
gpt4 key购买 nike

Roslyn 给了我们 deterministic builds几年前。
加上 NuGet lock files ,我们终于可以保证可重现的构建 .
我是 looking at the docs说我可以选择加入--use-lock-file Bootstraps use of lock file for a project. You can alternatively set RestorePackagesWithLockFile property in the project file并且在恢复时需要一个锁定文件:--locked-mode Enables locked mode for restore. This is useful in CI/CD scenarios where you would like to get the repeatable builds. This can be also by setting the RestoreLockedMode MSBuild property to true我正在尝试通过修改 Directory.Build.props在 repo 的根部:

   <PropertyGroup>
...
+ <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
当我跑 dotnet restore ,我看到了 lock生成的文件:
    benchmarks/Sentry.Benchmarks/packages.lock.json
samples/Sentry.Samples.AspNetCore.Basic/packages.lock.json
...
test/Sentry.Tests/packages.lock.json

现在,如果我尝试恢复: dotnet restore --locked-mode ,它完全失败。输出摘要如下:
/Users/bruno/git/sentry-dotnet/test/Sentry.Tests/Sentry.Tests.csproj : error NU1603: System.Private.DataContractSerialization 4.1.1 depends on System.Xml.XmlDocument (>= 4.0.1) but System.Xml.XmlDocument 4.0.1 was not found. An approximate best match of System.Xml.XmlDocument 4.3.0 was resolved. [/Users/bruno/git/sentry-dotnet/Sentry.sln]
/Users/bruno/git/sentry-dotnet/test/Sentry.Tests/Sentry.Tests.csproj : error NU1603: System.Xml.XPath.XmlDocument 4.0.1 depends on System.Xml.XmlDocument (>= 4.0.1) but System.Xml.XmlDocument 4.0.1 was not found. An approximate best match of System.Xml.XmlDocument 4.3.0 was resolved. [/Users/bruno/git/sentry-dotnet/Sentry.sln]
Restore failed in 383.47 ms for /Users/bruno/git/sentry-dotnet/test/Sentry.NLog.Tests/Sentry.NLog.Tests.csproj.
Restore failed in 370.7 ms for /Users/bruno/git/sentry-dotnet/test/Sentry.Testing/Sentry.Testing.csproj.
我一定在这里完全错了。
PS:我已将更改推送到分支和 opened a PR on GitHub如果有人有兴趣看一看。
编辑:2021 年 1 月:1 年半后,我再次尝试使用 .NET 5 SDK,但我仍然遇到问题:
https://github.com/getsentry/sentry-dotnet/pull/731
我试过 DisableImplicitNuGetFallbackFolder没有成功。锁定文件似乎是平台相关的。
在 CI 中,它在 macOS 上正常工作和 Linux但在 Windows 上失败.我在 Mac 上创建了锁定文件。我在 Windows 上拉了分支,它确实失败了:
error NU1403: Package content hash validation failed for System.Net.Http.4.3.0. The package is different than the last restore.
我敢打赌它使用文件路径分隔符,例如 /在计算散列时,这就是失败的原因。

最佳答案

通过添加 RuntimeIdentifiers 应该可以实现跨平台稳定的锁定文件给您的 PropertyGroup ,例如<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>

关于.net - NuGet 锁定文件无法使用 --locked-mode 还原,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57161512/

41 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com