Skip to content

Commit 4b52b5d

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 4b52b5d

32 files changed

Lines changed: 219 additions & 16 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: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ public class ProjectFactory : IProjectFactory, CoreV2.NuGet.IPropertyProvider, I
5151

5252
private readonly MSBuildAssemblyResolver _msbuildAssemblyResolver;
5353

54+
private readonly bool _deterministic;
55+
private readonly string _deterministicTimestamp;
56+
5457
// Packaging folders
5558
private const string ContentFolder = "content";
5659

@@ -66,13 +69,16 @@ public class ProjectFactory : IProjectFactory, CoreV2.NuGet.IPropertyProvider, I
6669
private const string ReferenceOutputAssembly = "ReferenceOutputAssembly";
6770
private const string TransformFileExtension = ".transform";
6871

72+
6973
[Import]
7074
public IMachineWideSettings MachineWideSettings { get; set; }
7175

7276
public static IProjectFactory ProjectCreator(PackArgs packArgs, string path)
7377
{
7478
return new ProjectFactory(packArgs.MsBuildDirectory.Value, path, packArgs.Properties)
7579
{
80+
_deterministic = packArgs.Deterministic,
81+
_deterministicTimestamp = packArgs.DeterministicTimestamp,
7682
IsTool = packArgs.Tool,
7783
LogLevel = packArgs.LogLevel,
7884
Logger = packArgs.Logger,
@@ -236,7 +242,11 @@ public PackageBuilder CreateBuilder(string basePath, NuGetVersion version, strin
236242
}
237243
}
238244

239-
builder = new PackageBuilder(false, Logger);
245+
// TODO is deterministic-ness tied in here?
246+
builder = new PackageBuilder(_deterministic, Logger)
247+
{
248+
DeterministicTimestamp = _deterministicTimestamp,
249+
};
240250

241251
try
242252
{
@@ -705,6 +715,7 @@ private PackageDependency CreateDependencyFromProject(dynamic project, Dictionar
705715
projectFactory.ProjectProperties = ProjectProperties;
706716
projectFactory.SymbolPackageFormat = SymbolPackageFormat;
707717
projectFactory.BuildProject();
718+
// TODO: does deterministicness matter here?
708719
var builder = new PackageBuilder();
709720

710721
projectFactory.ExtractMetadata(builder);

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)