Bru*_*cia 14 .net msbuild build nuget binary-reproducibility
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.propsrepo 的根目录来尝试它:
<PropertyGroup>
...
+ <RestorePackagesWithLockFile>true</RestorePackagesWithLockFile>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
当我运行时dotnet restore,我看到lock生成的文件:
benchmarks/Sentry.Benchmarks/packages.lock.json
samples/Sentry.Samples.AspNetCore.Basic/packages.lock.json
...
test/Sentry.Tests/packages.lock.json
Run Code Online (Sandbox Code Playgroud)
现在,如果我尝试恢复: 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.
Run Code Online (Sandbox Code Playgroud)
我一定在这里完全错了。
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.
Run Code Online (Sandbox Code Playgroud)
我敢打赌它使用文件路径分隔符,例如/在计算散列时,这就是失败的原因。
RuntimeIdentifiers通过添加到您的PropertyGroup,例如应该可以实现跨平台稳定的锁定文件<RuntimeIdentifiers>win-x64;linux-x64;osx-x64</RuntimeIdentifiers>
| 归档时间: |
|
| 查看次数: |
1338 次 |
| 最近记录: |