豆豆友情提示:这是一个非官方 GitHub 代理镜像,主要用于网络测试或访问加速。请勿在此进行登录、注册或处理任何敏感信息。进行这些操作请务必访问官方网站 github.com。 Raw 内容也通过此代理提供。
Skip to content

Commit 1f979fb

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 1f979fb

File tree

32 files changed

+218
-16
lines changed

32 files changed

+218
-16
lines changed

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: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class ProjectFactory : IProjectFactory, CoreV2.NuGet.IPropertyProvider, I
4040

4141
private IEnvironmentVariableReader _environmentVariableReader;
4242

43+
private bool _deterministic;
44+
private string _deterministicTimestamp;
45+
4346
// Files we want to always exclude from the resulting package
4447
private static readonly HashSet<string> ExcludeFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase) {
4548
NuGetConstants.PackageReferenceFile,
@@ -73,6 +76,8 @@ public static IProjectFactory ProjectCreator(PackArgs packArgs, string path)
7376
{
7477
return new ProjectFactory(packArgs.MsBuildDirectory.Value, path, packArgs.Properties)
7578
{
79+
_deterministic = packArgs.Deterministic,
80+
_deterministicTimestamp = packArgs.DeterministicTimestamp,
7681
IsTool = packArgs.Tool,
7782
LogLevel = packArgs.LogLevel,
7883
Logger = packArgs.Logger,
@@ -236,7 +241,11 @@ public PackageBuilder CreateBuilder(string basePath, NuGetVersion version, strin
236241
}
237242
}
238243

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

241250
try
242251
{
@@ -705,6 +714,7 @@ private PackageDependency CreateDependencyFromProject(dynamic project, Dictionar
705714
projectFactory.ProjectProperties = ProjectProperties;
706715
projectFactory.SymbolPackageFormat = SymbolPackageFormat;
707716
projectFactory.BuildProject();
717+
// TODO: does deterministicness matter here?
708718
var builder = new PackageBuilder();
709719

710720
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)