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
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:如果有人有兴趣看一下,我已经将更改推送到一个分支并在 GitHub 上打开了一个 PR 。
编辑: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.
我敢打赌它正在使用文件路径分隔符,例如/
在计算哈希时,这就是失败的原因。