NuGet 锁定文件无法使用 --锁定模式还原



Roslyn几年前给了我们deterministic构建。

随着NuGet 锁定文件的添加,我们终于可以保证可重现的生成

我正在查看说我可以选择加入

的文档--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来尝试:

<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:我已经将更改推送到一个分支,并在GitHub上打开了一个PR,如果有兴趣看一下。

编辑:2021 年 1 月:1 年半后,我再次尝试使用 .NET 5 SDK,但仍然遇到问题: https://github.com/getsentry/sentry-dotnet/pull/731

我试过DisableImplicitNuGetFallbackFolder但没有成功。锁定文件似乎取决于平台。

在 CI 中,它在macOSLinux上正常工作,但在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.

我敢打赌,在计算哈希值时,它会使用文件路径分隔符,例如/,这就是失败的原因。

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

最新更新