Skip to content

Commit e469207

Browse files
committed
Fix
1 parent 5d67416 commit e469207

File tree

5 files changed

+42
-39
lines changed

5 files changed

+42
-39
lines changed

src/BuiltInTools/dotnet-watch/HotReloadDotNetWatcher.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,8 +611,7 @@ private bool AcceptChange(ChangedPath change)
611611
return false;
612612
}
613613

614-
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) &&
615-
PathUtilities.GetContainingDirectories(path).FirstOrDefault(IsHiddenWindowsPath) is { } containingHiddenDir)
614+
if (PathUtilities.GetContainingDirectories(path).FirstOrDefault(IsHiddenDirectory) is { } containingHiddenDir)
616615
{
617616
Context.Reporter.Report(MessageDescriptor.IgnoringChangeInHiddenDirectory, containingHiddenDir, kind, path);
618617
return false;
@@ -621,15 +620,20 @@ private bool AcceptChange(ChangedPath change)
621620
return true;
622621
}
623622

624-
private static bool IsHiddenWindowsPath(string path)
625-
// Note: the device root directory on Windows has hidden attribute:
626-
=> File.GetAttributes(path).HasFlag(FileAttributes.Hidden) && Path.GetDirectoryName(path) != null;
627-
628-
internal static string FormatTimestamp(DateTime time)
629-
=> time.ToString("HH:mm:ss.fffffff");
623+
// Directory name starts with '.' on Unix is considered hidden.
624+
// Apply the same convention on Windows as well (instead of checking for hidden attribute).
625+
// This is consistent with SDK rules for default item exclusions:
626+
// https://github.com/dotnet/sdk/blob/124be385f90f2c305dde2b817cb470e4d11d2d6b/src/Tasks/Microsoft.NET.Build.Tasks/targets/Microsoft.NET.Sdk.DefaultItems.targets#L42
627+
private static bool IsHiddenDirectory(string dir)
628+
=> Path.GetFileName(dir).StartsWith('.');
630629

631630
private static IReadOnlySet<string> GetProjectOutputDirectories(ProjectGraph projectGraph)
632631
{
632+
// TODO: https://github.com/dotnet/sdk/issues/45539
633+
// Consider evaluating DefaultItemExcludes and DefaultExcludesInProjectFolder msbuild properties using
634+
// https://github.com/dotnet/msbuild/blob/37eb419ad2c986ac5530292e6ee08e962390249e/src/Build/Globbing/MSBuildGlob.cs
635+
// to determine which directories should be excluded.
636+
633637
var projectOutputDirectories = new HashSet<string>(PathUtilities.OSSpecificPathComparer);
634638

635639
foreach (var projectNode in projectGraph.ProjectNodes)

src/BuiltInTools/dotnet-watch/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"dotnet-watch": {
44
"commandName": "Project",
55
"commandLineArgs": "--verbose /bl:DotnetRun.binlog",
6-
"workingDirectory": "C:\\sdk1\\artifacts\\tmp\\Debug\\RenameDirecto---333D0BB9\\AppWithDeps",
6+
"workingDirectory": "$(RepoRoot)src\\Assets\\TestProjects\\BlazorWasmWithLibrary\\blazorwasm",
77
"environmentVariables": {
88
"DOTNET_WATCH_DEBUG_SDK_DIRECTORY": "$(RepoRoot)artifacts\\bin\\redist\\$(Configuration)\\dotnet\\sdk\\$(Version)",
99
"DCP_IDE_REQUEST_TIMEOUT_SECONDS": "100000",

test/dotnet-watch.Tests/HotReload/ApplyDeltaTests.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,11 @@ public async Task Razor_Component_ScopedCssAndStaticAssets()
428428
App.Process.ClearOutput();
429429
}
430430

431-
[PlatformSpecificFact(TestPlatforms.Windows | TestPlatforms.OSX)]
431+
/// <summary>
432+
/// Currently only works on Windows.
433+
/// Add TestPlatforms.OSX once https://github.com/dotnet/sdk/issues/45521 is fixed.
434+
/// </summary>
435+
[PlatformSpecificFact(TestPlatforms.Windows)]
432436
public async Task MauiBlazor()
433437
{
434438
var testAsset = TestAssets.CopyTestAsset("WatchMauiBlazor")

test/dotnet-watch.Tests/HotReload/RuntimeProcessLauncherTests.cs

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -533,40 +533,38 @@ public enum DirectoryKind
533533
Obj,
534534
}
535535

536-
[PlatformSpecificTheory(TestPlatforms.Windows)]
537-
[CombinatorialData]
538-
public Task IgnoredChange_Windows(bool isExisting, bool isIncluded, DirectoryKind directoryKind)
539-
=> IgnoredChange(isExisting, isIncluded, directoryKind);
540-
541-
[PlatformSpecificTheory(TestPlatforms.AnyUnix)]
536+
[Theory]
542537
[CombinatorialData]
543-
public Task IgnoredChange_Unix(
538+
public async Task IgnoredChange(
544539
bool isExisting,
545540
bool isIncluded,
546-
[CombinatorialValues(DirectoryKind.Obj, DirectoryKind.Bin, DirectoryKind.Ordinary)] DirectoryKind directoryKind)
547-
=> IgnoredChange(isExisting, isIncluded, directoryKind);
548-
549-
private async Task IgnoredChange(bool isExisting, bool isIncluded, DirectoryKind directoryKind)
541+
[CombinatorialValues] DirectoryKind directoryKind)
550542
{
551543
var testAsset = CopyTestAsset("WatchNoDepsApp", [isExisting, isIncluded, directoryKind]);
552544

553545
var workingDirectory = testAsset.Path;
546+
string dir;
554547

555-
var objDir = Path.Combine(workingDirectory, "obj", "Debug", ToolsetInfo.CurrentTargetFramework);
556-
var binDir = Path.Combine(workingDirectory, "bin", "Debug", ToolsetInfo.CurrentTargetFramework);
548+
switch (directoryKind)
549+
{
550+
case DirectoryKind.Bin:
551+
dir = Path.Combine(workingDirectory, "bin", "Debug", ToolsetInfo.CurrentTargetFramework);
552+
break;
557553

558-
var hiddenDir = Path.Combine(workingDirectory, "hidden");
559-
Directory.CreateDirectory(hiddenDir);
560-
File.SetAttributes(hiddenDir, FileAttributes.Hidden | FileAttributes.Directory);
554+
case DirectoryKind.Obj:
555+
dir = Path.Combine(workingDirectory, "obj", "Debug", ToolsetInfo.CurrentTargetFramework);
556+
break;
557+
558+
case DirectoryKind.Hidden:
559+
dir = Path.Combine(workingDirectory, ".dir");
560+
break;
561+
562+
default:
563+
dir = workingDirectory;
564+
break;
565+
}
561566

562567
var extension = isIncluded ? ".cs" : ".txt";
563-
var dir = directoryKind switch
564-
{
565-
DirectoryKind.Bin => binDir,
566-
DirectoryKind.Obj => objDir,
567-
DirectoryKind.Hidden => hiddenDir,
568-
_ => workingDirectory,
569-
};
570568

571569
Directory.CreateDirectory(dir);
572570

@@ -576,7 +574,7 @@ private async Task IgnoredChange(bool isExisting, bool isIncluded, DirectoryKind
576574
{
577575
File.WriteAllText(path, "class C { int F() => 1; }");
578576

579-
if (isIncluded && directoryKind is DirectoryKind.Bin or DirectoryKind.Obj)
577+
if (isIncluded && directoryKind is DirectoryKind.Bin or DirectoryKind.Obj or DirectoryKind.Hidden)
580578
{
581579
var project = Path.Combine(workingDirectory, "WatchNoDepsApp.csproj");
582580
File.WriteAllText(project, File.ReadAllText(project).Replace(

test/dotnet-watch.Tests/Watch/Utilities/DotNetWatchTestBase.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,11 @@ public void Log(string message)
2929
public void UpdateSourceFile(string path, string text)
3030
{
3131
WriteAllText(path, text);
32-
Log($"File '{path}' updated ({HotReloadDotNetWatcher.FormatTimestamp(File.GetLastWriteTimeUtc(path))}).");
32+
Log($"File '{path}' updated.");
3333
}
3434

3535
public void UpdateSourceFile(string path, Func<string, string> contentTransform)
36-
{
37-
WriteAllText(path, contentTransform(File.ReadAllText(path, Encoding.UTF8)));
38-
Log($"File '{path}' updated.");
39-
}
36+
=> UpdateSourceFile(path, contentTransform(File.ReadAllText(path, Encoding.UTF8)));
4037

4138
/// <summary>
4239
/// Replacement for <see cref="File.WriteAllText"/>, which fails to write to hidden file

0 commit comments

Comments
 (0)