Skip to content

Commit 19b6b2f

Browse files
committed
Add support for DeterministicTimestamp
Add support for a new MSBuild property that developrs can use to override the deterministic timestamp. This allows developers to override the auto-computed timetsamps, and enables working around processes/tools that don't like the fixed/old timetsamps.
1 parent ca1ea21 commit 19b6b2f

File tree

13 files changed

+111
-35
lines changed

13 files changed

+111
-35
lines changed

src/NuGet.Core/NuGet.Build.Tasks.Pack/IPackTaskRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public interface IPackTaskRequest<TItem>
7676
string PackageLicenseFile { get; }
7777
string Readme { get; }
7878
bool Deterministic { get; }
79+
string DeterministicTimestamp { get; }
7980
string PackageIcon { get; }
8081
}
8182
}

src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTask.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ internal PackTask(IEnvironmentVariableReader environmentVariableReader)
9292
public string PackageLicenseExpressionVersion { get; set; }
9393
public string Readme { get; set; }
9494
public bool Deterministic { get; set; }
95+
public string DeterministicTimestamp { get; set; }
9596
public string PackageIcon { get; set; }
9697
public ILogger Logger => new MSBuildLogger(Log);
9798

@@ -225,6 +226,7 @@ private IPackTaskRequest<IMSBuildItem> GetRequest()
225226
PackageLicenseExpressionVersion = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageLicenseExpressionVersion),
226227
Readme = MSBuildStringUtility.TrimAndGetNullForEmpty(Readme),
227228
Deterministic = Deterministic,
229+
DeterministicTimestamp = MSBuildStringUtility.TrimAndGetNullForEmpty(DeterministicTimestamp),
228230
PackageIcon = MSBuildStringUtility.TrimAndGetNullForEmpty(PackageIcon),
229231
};
230232
}

src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskLogic.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public PackArgs GetPackArgs(IPackTaskRequest<IMSBuildItem> request)
4343
NoPackageAnalysis = request.NoPackageAnalysis,
4444
NoDefaultExcludes = request.NoDefaultExcludes,
4545
Deterministic = request.Deterministic,
46+
DeterministicTimestamp = request.DeterministicTimestamp,
4647
WarningProperties = WarningProperties.GetWarningProperties(request.TreatWarningsAsErrors, request.WarningsAsErrors, request.NoWarn, request.WarningsNotAsErrors),
4748
PackTargetArgs = new MSBuildPackTargetArgs()
4849
};
@@ -134,6 +135,14 @@ public PackageBuilder GetPackageBuilder(IPackTaskRequest<IMSBuildItem> request)
134135
PackageTypes = ParsePackageTypes(request)
135136
};
136137

138+
if (request.Deterministic)
139+
{
140+
if (request.DeterministicTimestamp != null)
141+
{
142+
builder.DeterministicTimestamp = request.DeterministicTimestamp;
143+
}
144+
}
145+
137146
if (request.DevelopmentDependency)
138147
{
139148
builder.DevelopmentDependency = true;

src/NuGet.Core/NuGet.Build.Tasks.Pack/PackTaskRequest.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public class PackTaskRequest : IPackTaskRequest<IMSBuildItem>
7171
public string PackageLicenseExpression { get; set; }
7272
public string PackageLicenseExpressionVersion { get; set; }
7373
public bool Deterministic { get; set; }
74+
public string DeterministicTimestamp { get; set; }
7475
public string PackageIcon { get; set; }
7576
}
7677
}

src/NuGet.Core/NuGet.Build.Tasks/NuGet.Build.Tasks.Pack.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ Copyright (c) .NET Foundation. All rights reserved.
279279
PackageLicenseExpressionVersion="$(PackageLicenseExpressionVersion)"
280280
Readme="$(PackageReadmeFile)"
281281
Deterministic="$(Deterministic)"
282+
DeterministicTimestamp="$(DeterministicTimestamp)"
282283
PackageIcon="$(PackageIcon)"
283284
/>
284285
</Target>

src/NuGet.Core/NuGet.Commands/CommandArgs/PackArgs.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class PackArgs
4545
public bool Tool { get; set; }
4646
public string Version { get; set; }
4747
public bool Deterministic { get; set; }
48+
public string DeterministicTimestamp { get; set; }
4849
public WarningProperties WarningProperties { get; set; }
4950
public MSBuildPackTargetArgs PackTargetArgs { get; set; }
5051
public Dictionary<string, string> Properties

src/NuGet.Core/NuGet.Commands/CommandRunners/PackCommandRunner.cs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -446,23 +446,31 @@ private PackageBuilder CreatePackageBuilderFromNuspec(string path)
446446
_packArgs.Logger = new PackCollectorLogger(_packArgs.Logger, _packArgs.WarningProperties);
447447
}
448448

449+
PackageBuilder result;
450+
449451
if (string.IsNullOrEmpty(_packArgs.BasePath))
450452
{
451-
return new PackageBuilder(
453+
result = new PackageBuilder(
452454
path,
453455
_packArgs.GetPropertyValue,
454456
!_packArgs.ExcludeEmptyDirectories,
455457
_packArgs.Deterministic,
456458
_packArgs.Logger);
457459
}
460+
else
461+
{
462+
result = new PackageBuilder(
463+
path,
464+
_packArgs.BasePath,
465+
_packArgs.GetPropertyValue,
466+
!_packArgs.ExcludeEmptyDirectories,
467+
_packArgs.Deterministic,
468+
_packArgs.Logger);
469+
}
458470

459-
return new PackageBuilder(
460-
path,
461-
_packArgs.BasePath,
462-
_packArgs.GetPropertyValue,
463-
!_packArgs.ExcludeEmptyDirectories,
464-
_packArgs.Deterministic,
465-
_packArgs.Logger);
471+
result.DeterministicTimestamp = _packArgs.DeterministicTimestamp;
472+
473+
return result;
466474
}
467475

468476
private bool BuildFromProjectFile(string path)

src/NuGet.Core/NuGet.Commands/PublicAPI/net472/PublicAPI.Shipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ NuGet.Commands.PackArgs.Build.set -> void
340340
~NuGet.Commands.PackArgs.CurrentDirectory.set -> void
341341
NuGet.Commands.PackArgs.Deterministic.get -> bool
342342
NuGet.Commands.PackArgs.Deterministic.set -> void
343+
~NuGet.Commands.PackArgs.DeterministicTimestamp.get -> string
344+
~NuGet.Commands.PackArgs.DeterministicTimestamp.set -> void
343345
~NuGet.Commands.PackArgs.Exclude.get -> System.Collections.Generic.IEnumerable<string>
344346
~NuGet.Commands.PackArgs.Exclude.set -> void
345347
NuGet.Commands.PackArgs.ExcludeEmptyDirectories.get -> bool

src/NuGet.Core/NuGet.Commands/PublicAPI/net8.0/PublicAPI.Shipped.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,8 @@ NuGet.Commands.PackArgs.Build.set -> void
340340
~NuGet.Commands.PackArgs.CurrentDirectory.set -> void
341341
NuGet.Commands.PackArgs.Deterministic.get -> bool
342342
NuGet.Commands.PackArgs.Deterministic.set -> void
343+
~NuGet.Commands.PackArgs.DeterministicTimestamp.get -> string
344+
~NuGet.Commands.PackArgs.DeterministicTimestamp.set -> void
343345
~NuGet.Commands.PackArgs.Exclude.get -> System.Collections.Generic.IEnumerable<string>
344346
~NuGet.Commands.PackArgs.Exclude.set -> void
345347
NuGet.Commands.PackArgs.ExcludeEmptyDirectories.get -> bool

src/NuGet.Core/NuGet.Packaging/GlobalSuppressions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'IEnumerable<string> PackageArchiveReader.CopyFiles(string destination, IEnumerable<string> packageFiles, ExtractPackageFileDelegate extractFile, ILogger logger, CancellationToken token)', validate parameter 'packageFiles' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageArchiveReader.CopyFiles(System.String,System.Collections.Generic.IEnumerable{System.String},NuGet.Packaging.Core.ExtractPackageFileDelegate,NuGet.Common.ILogger,System.Threading.CancellationToken)~System.Collections.Generic.IEnumerable{System.String}")]
4545
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'IEnumerable<ZipFilePair> PackageArchiveReader.EnumeratePackageEntries(IEnumerable<string> packageFiles, string packageDirectory)', validate parameter 'packageFiles' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageArchiveReader.EnumeratePackageEntries(System.Collections.Generic.IEnumerable{System.String},System.String)~System.Collections.Generic.IEnumerable{NuGet.Packaging.ZipFilePair}")]
4646
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'Stream PackageArchiveReader.GetStream(string path)', validate parameter 'path' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageArchiveReader.GetStream(System.String)~System.IO.Stream")]
47-
[assembly: SuppressMessage("Build", "CA1801:Parameter deterministic of method .ctor is never used. Remove the parameter or use it in the method body.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageBuilder.#ctor(System.Boolean,System.Boolean)")]
4847
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void PackageBuilder.AddFiles(string basePath, string source, string destination, string exclude = null)', validate parameter 'source' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageBuilder.AddFiles(System.String,System.String,System.String,System.String)")]
4948
[assembly: SuppressMessage("Build", "CA1822:Member GenerateRelationshipId does not access instance data and can be marked as static (Shared in VisualBasic)", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageBuilder.GenerateRelationshipId(System.String)~System.String")]
5049
[assembly: SuppressMessage("Build", "CA1062:In externally visible method 'void PackageBuilder.Populate(ManifestMetadata manifestMetadata)', validate parameter 'manifestMetadata' is non-null before using it. If appropriate, throw an ArgumentNullException when the argument is null or add a Code Contract precondition asserting non-null argument.", Justification = "<Pending>", Scope = "member", Target = "~M:NuGet.Packaging.PackageBuilder.Populate(NuGet.Packaging.ManifestMetadata)")]

0 commit comments

Comments
 (0)