dotnet / dotnet/msbuild

Standardize LastWriteTime value for nonexistent files

Open
#3,699 1 comment 0 reactions 0 assignees View on GitHub
triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 13h
Merged PRs (30d)
133

Description

MSBuild has mixed usage on whether ```LastWriteTime``` of a nonexistent file is represented by ```DateTime.MinValue``` or ```DateTime.FromFIleTimeUtc(0)``` (.NET API's choice of value).

This leads to boilerplate code converting from one format to the other:
```csharp
DateTime lastWriteTime = File.GetLastWriteTimeUtc(fullPath);
bool fileExists = lastWriteTime != DateTime.FromFileTimeUtc(0);

fileModifiedTime = fileExists ? lastWriteTime : DateTime.MinValue;
```

Unclear results requiring to dig through code (what if ```componentTimestamp``` was populated via ```NativeMethodsShared``` returning ```DateTime.MinValue```?):
```csharp
if (DateTime.Compare(File.GetLastWriteTime(ReferenceInfo.strippedTypeLibPath), componentTimestamp) != 0)
{
// blah blah
}
```

Or having to check both values:
```csharp
private bool IsExistingFileTime(DateTime lastModified)
{
return lastModified != DateTime.MinValue && lastModified != DateTime.FromFileTimeUtc(0);
}
```

Which is unavoidable in some spots due to delegates (is this ```NativeMethodsShared.GetLastWriteFileUtcTime()``` or ```File.GetLastWriteTimeUtc()```?):
```csharp
internal delegate DateTime GetLastWriteTime(string path);
```

I think the ideal solution is to follow what's already returned by .NET APIs and use a constant for ```DateTime.FromFileTimeUtc(0)```.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing the usages of File.GetLastWriteTimeUtc, NativeMethodsShared.GetLastWriteFileUtcTime(), and the GetLastWriteTime delegate mentioned in the issue. Compare how nonexistent-file timestamps are handled across those call sites and identify the affected build logic. Done means the project uses one documented sentinel consistently without the existing conversion or dual-value checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
build-system
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.