【发布时间】:2019-12-01 08:15:19
【问题描述】:
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:
<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.
我敢打赌它在计算哈希时使用了文件路径分隔符,例如 /,这就是失败的原因。
【问题讨论】:
-
嗨,这有什么更新吗?我遇到了完全相同的问题。
标签: .net build msbuild nuget binary-reproducibility