Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I do a deterministic build locally (ContinuousIntegrationBuild flag)?

When I attempt to publish my package using NuGet Package Explorer, I see the following warning:

Non-Deterministic

Deterministic (dll/exe): Non deterministic
Ensure that the following property is enabled for CI builds
and you're using at least the 2.1.300 SDK:

<ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>

However, when I add that property to the PropertyGroup (as described here), VS 2019 freaks out so badly I literally need to ctrl+alt+delete to close it.

According to this page the property name is <Deterministic>, but that doesn't seem to do anything at all.

So how do I get deterministic builds to work?

Visual Studio 2019, v16.7.1
.Net SDK 3.1.401 (LTS)

like image 424
BlueRaja - Danny Pflughoeft Avatar asked Aug 13 '20 04:08

BlueRaja - Danny Pflughoeft


Video Answer


2 Answers

An easier answer is to not mess with .csproj files (urgh!) and do this via the command line, in your CI script.

add the /p:ContinuousIntegrationBuild=true argument to the dotnet pack command.

dotnet pack 
    -c $env:CONFIGURATION 
    /p:ContinuousIntegrationBuild=true 
    -p:PackageVersion=$env:APPVEYOR_BUILD_VERSION

(make this all one line. I've multi-lined it, for readability)

NOTE: the --no-build argument is NOT here. We need to build this again. Or you add that param to the build step, before this.

This is taken from an example CI file I use. So when I'm in release mode, I pack the library into a nuget and publish it.

Keeps things clean and out of your .csproj file (which is very hard to grok and maintain).

like image 65
Pure.Krome Avatar answered Nov 02 '22 10:11

Pure.Krome


I basically just found the answer in this blogpost:

While deterministic builds are enabled by default in .NET SDK projects, there is an extra property, ContinuousIntegrationBuild, to set on the build server to normalize stored file paths. These should not be enabled during local dev or the debugger won’t be able to find the local source files.

<PropertyGroup Condition="'$(TF_BUILD)' == 'true'">
  <ContinuousIntegrationBuild>true</ContinuousIntegrationBuild>
</PropertyGroup>
like image 44
David Perfors Avatar answered Nov 02 '22 09:11

David Perfors