Skip to content

Commit 6e87959

Browse files
committed
Re-enable support for deterministic pack
Make NuGet pack more determinisitic, by default. This makes `Deterministic` property (default = `true`) work again for nuget pack via msbuild. It adds support for `DeterministicTimestamp` property (default = `true`) too. For more details about the properties and the design goals, see: - NuGet/Home#14785 - https://github.com/NuGet/Home/main/accepted/2026/deterministic-pack-revisited.md Fixes: NuGet/Home#8601
1 parent b5ca9db commit 6e87959

32 files changed

Lines changed: 208 additions & 15 deletions

src/NuGet.Clients/NuGet.CommandLine/Commands/PackCommand.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ public Dictionary<string, string> Properties
103103
[Option(typeof(NuGetCommand), "PackageCommandConfigFile")]
104104
public new string ConfigFile { get; set; }
105105

106+
[Option(typeof(NuGetCommand), "PackageCommandDeterministic")]
107+
public bool Deterministic { get; set; }
108+
109+
[Option(typeof(NuGetCommand), "PackageCommandDeterministicTimestamp")]
110+
public string DeterministicTimestamp { get; set; }
111+
106112
public override void ExecuteCommand()
107113
{
108114
var packArgs = new PackArgs();
@@ -111,6 +117,8 @@ public override void ExecuteCommand()
111117
packArgs.OutputDirectory = OutputDirectory;
112118
packArgs.BasePath = BasePath;
113119
packArgs.MsBuildDirectory = new Lazy<string>(() => MsBuildUtility.GetMsBuildDirectoryFromMsBuildPath(MSBuildPath, MSBuildVersion, Console).Value.Path);
120+
packArgs.Deterministic = Deterministic;
121+
packArgs.DeterministicTimestamp = DeterministicTimestamp;
114122

115123
if (!string.IsNullOrEmpty(PackagesDirectory))
116124
{

src/NuGet.Clients/NuGet.CommandLine/Commands/ProjectFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ public PackageBuilder CreateBuilder(string basePath, NuGetVersion version, strin
236236
}
237237
}
238238

239+
// TODO is deterministic-ness tied in here?
239240
builder = new PackageBuilder(false, Logger);
240241

241242
try

src/NuGet.Clients/NuGet.CommandLine/NuGetCommand.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/NuGet.Clients/NuGet.CommandLine/NuGetCommand.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,9 @@ nuget trusted-signers Remove -Name TrustedRepo</value>
844844
<data name="PackageCommandDeterministic" xml:space="preserve">
845845
<value>Specify if the command should create a deterministic package. Multiple invocations of the pack command will create the exact same package.</value>
846846
</data>
847+
<data name="PackageCommandDeterministicTimestamp" xml:space="preserve">
848+
<value>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</value>
849+
</data>
847850
<data name="ClientCertificatesCommandFilePathDescription" xml:space="preserve">
848851
<value>Path to certificate file.</value>
849852
</data>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.cs.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">Určete, jestli má příkaz vytvořit deterministický balíček. Vícenásobné vyvolání příkazu pack vytvoří úplně stejný balíček.</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">Určuje nejméně jeden vzor zástupných znaků, který se má vyloučit při vytváření balíčku.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.de.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">Geben Sie an, ob der Befehl ein deterministisches Paket erstellen soll. Durch mehrere Aufrufe des Paketbefehls wird genau dasselbe Paket erstellt.</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">Gibt mindestens ein Platzhaltermuster an, das beim Erstellen eines Pakets ausgeschlossen werden soll.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.es.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">Especifique si el comando debe crear un paquete determinista. Varias invocaciones del comando pack crearán exactamente el mismo paquete.</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">Especifica uno o varios patrones de comodines que se excluirán al crear un paquete.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.fr.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">Spécifiez si la commande doit créer un package déterministe. Plusieurs appels de la commande pack créent exactement le même package.</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">Spécifie un ou plusieurs modèles à caractère générique à exclure durant la création d'un package.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.it.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">Specificare se il comando deve creare un pacchetto deterministico. Le chiamate multiple del comando pack creeranno lo stesso pacchetto.</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">Specifica uno o più caratteri jolly da escludere durante la creazione di un pacchetto.</target>

src/NuGet.Clients/NuGet.CommandLine/xlf/NuGetCommand.ja.xlf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,11 @@ nuget pack foo.nuspec -Version 2.1.0</target>
601601
<target state="translated">コマンドで決定論的パッケージを作成する必要があるかどうかを指定します。パック コマンドを複数回呼び出すと、まったく同じパッケージが作成されます。</target>
602602
<note />
603603
</trans-unit>
604+
<trans-unit id="PackageCommandDeterministicTimestamp">
605+
<source>Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</source>
606+
<target state="new">Specify the timestamp this command should use when creating a deterministic package. Multiple invocations of the pack command will create the exact same package.</target>
607+
<note />
608+
</trans-unit>
604609
<trans-unit id="PackageCommandExcludeDescription">
605610
<source>Specifies one or more wildcard patterns to exclude when creating a package.</source>
606611
<target state="translated">パッケージの作成時に除外する 1 つまたは複数のワイルドカード パターンを指定します。</target>

0 commit comments

Comments
 (0)