Skip to content

Commit d5430c6

Browse files
committed
1
1 parent 8094fb0 commit d5430c6

File tree

4 files changed

+32
-13
lines changed

4 files changed

+32
-13
lines changed

src/BuiltInTools/dotnet-watch/HotReload/HotReloadDotNetWatcher.cs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void FileChangedCallback(ChangedPath change)
189189

190190
fileChangedCallback = FileChangedCallback;
191191
fileWatcher.OnFileChange += fileChangedCallback;
192-
ReportWatchingForChanges();
192+
_context.Logger.Log(MessageDescriptor.WaitingForChanges);
193193

194194
// Hot Reload loop - exits when the root process needs to be restarted.
195195
bool extendTimeout = false;
@@ -772,12 +772,6 @@ internal static IEnumerable<ChangedPath> NormalizePathChanges(IEnumerable<Change
772772
.Where(item => item != null)
773773
.Select(item => item!.Value);
774774

775-
private void ReportWatchingForChanges()
776-
{
777-
_context.Logger.Log(MessageDescriptor.WaitingForChanges
778-
.WithSeverityWhen(MessageSeverity.Output, _context.EnvironmentOptions.TestFlags.HasFlag(TestFlags.ElevateWaitingForChangesMessageSeverity)));
779-
}
780-
781775
private void ReportFileChanges(IReadOnlyList<ChangedFile> changedFiles)
782776
{
783777
Report(kind: ChangeKind.Add);
@@ -823,6 +817,9 @@ private async ValueTask<EvaluationResult> EvaluateRootProjectAsync(bool restore,
823817
{
824818
cancellationToken.ThrowIfCancellationRequested();
825819

820+
_context.Logger.LogInformation("Evaluating projects ...");
821+
var stopwatch = Stopwatch.StartNew();
822+
826823
var result = EvaluationResult.TryCreate(
827824
_context.RootProjectOptions.ProjectPath,
828825
_context.RootProjectOptions.BuildArguments,
@@ -832,6 +829,8 @@ private async ValueTask<EvaluationResult> EvaluateRootProjectAsync(bool restore,
832829
restore,
833830
cancellationToken);
834831

832+
_context.Logger.LogInformation("Evaluation completed in {Time}ms.", stopwatch.ElapsedMilliseconds);
833+
835834
if (result != null)
836835
{
837836
return result;

src/BuiltInTools/dotnet-watch/HotReload/IncrementalMSBuildWorkspace.cs

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ namespace Microsoft.DotNet.Watch;
1515
internal sealed class IncrementalMSBuildWorkspace : Workspace
1616
{
1717
private readonly ILogger _logger;
18+
private int _solutionUpdateId;
1819

1920
public IncrementalMSBuildWorkspace(ILogger logger)
2021
: base(MSBuildMefHostServices.DefaultServices, WorkspaceKind.MSBuild)
@@ -35,6 +36,9 @@ public IncrementalMSBuildWorkspace(ILogger logger)
3536

3637
public async Task UpdateProjectConeAsync(string rootProjectPath, CancellationToken cancellationToken)
3738
{
39+
_logger.LogInformation("Loading projects ...");
40+
41+
var stopwatch = Stopwatch.StartNew();
3842
var oldSolution = CurrentSolution;
3943

4044
var loader = new MSBuildProjectLoader(this);
@@ -94,9 +98,11 @@ public async Task UpdateProjectConeAsync(string rootProjectPath, CancellationTok
9498
.WithCompilationOutputInfo(newProjectInfo.CompilationOutputInfo));
9599
}
96100

97-
await ReportSolutionFilesAsync(SetCurrentSolution(newSolution), cancellationToken);
101+
await UpdateSolutionAsync(newSolution, operationDisplayName: "project update", cancellationToken);
98102
UpdateReferencesAfterAdd();
99103

104+
_logger.LogInformation("Projects loaded in {Time}ms.", stopwatch.ElapsedMilliseconds);
105+
100106
ProjectReference MapProjectReference(ProjectReference pr)
101107
// Only C# and VB projects are loaded by the MSBuildProjectLoader, so some references might be missing.
102108
// When a new project is added along with a new project reference the old project id is also null.
@@ -154,6 +160,8 @@ public async ValueTask UpdateFileContentAsync(IEnumerable<ChangedFile> changedFi
154160

155161
var newText = await GetSourceTextAsync(changedFile.FilePath, oldText.Encoding, oldText.ChecksumAlgorithm, cancellationToken);
156162

163+
_logger.LogDebug("Updating document text of '{FilePath}'.", changedFile.FilePath);
164+
157165
updatedSolution = textDocument switch
158166
{
159167
Document document => document.WithText(newText).Project.Solution,
@@ -166,7 +174,7 @@ public async ValueTask UpdateFileContentAsync(IEnumerable<ChangedFile> changedFi
166174

167175
updatedSolution = RemoveDocuments(updatedSolution, documentsToRemove);
168176

169-
await ReportSolutionFilesAsync(SetCurrentSolution(updatedSolution), cancellationToken);
177+
await UpdateSolutionAsync(updatedSolution, operationDisplayName: "document update", cancellationToken);
170178
}
171179

172180
private static Solution RemoveDocuments(Solution solution, IEnumerable<DocumentId> ids)
@@ -217,9 +225,19 @@ private static async ValueTask<SourceText> GetSourceTextAsync(string filePath, E
217225
return null;
218226
}
219227

220-
public async Task ReportSolutionFilesAsync(Solution solution, CancellationToken cancellationToken)
228+
private Task UpdateSolutionAsync(Solution newSolution, string operationDisplayName, CancellationToken cancellationToken)
229+
=> ReportSolutionFilesAsync(SetCurrentSolution(newSolution), Interlocked.Increment(ref _solutionUpdateId), operationDisplayName, cancellationToken);
230+
231+
private async Task ReportSolutionFilesAsync(Solution solution, int updateId, string operationDisplayName, CancellationToken cancellationToken)
221232
{
222-
_logger.LogDebug("Solution: {Path}", solution.FilePath);
233+
//if (!_logger.IsEnabled(LogLevel.Debug))
234+
//{
235+
// return;
236+
//}
237+
238+
var stopwatch = Stopwatch.StartNew();
239+
240+
_logger.LogDebug("Solution after {Operation}: v{Version}", operationDisplayName, updateId);
223241
foreach (var project in solution.Projects)
224242
{
225243
_logger.LogDebug(" Project: {Path}", project.FilePath);
@@ -240,6 +258,8 @@ public async Task ReportSolutionFilesAsync(Solution solution, CancellationToken
240258
}
241259
}
242260

261+
_logger.LogInformation("Solution reported in {Time}ms.", stopwatch.ElapsedMilliseconds);
262+
243263
async ValueTask InspectDocumentAsync(TextDocument document, string kind)
244264
{
245265
var text = await document.GetTextAsync(cancellationToken);

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",
6-
"workingDirectory": "C:\\bugs\\9756\\aspire-watch-start-issue\\Aspire.AppHost",
6+
"workingDirectory": "C:\\temp\\Razor",
77
"environmentVariables": {
88
"DOTNET_WATCH_DEBUG_SDK_DIRECTORY": "$(RepoRoot)artifacts\\bin\\redist\\$(Configuration)\\dotnet\\sdk\\$(Version)",
99
"DCP_IDE_REQUEST_TIMEOUT_SECONDS": "100000",

src/BuiltInTools/dotnet-watch/UI/IReporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public MessageDescriptor WithSeverityWhen(MessageSeverity severity, bool conditi
186186
public static readonly MessageDescriptor ProjectsRestarted = Create("Projects restarted ({0})", Emoji.HotReload, MessageSeverity.Verbose);
187187
public static readonly MessageDescriptor ProjectDependenciesDeployed = Create("Project dependencies deployed ({0})", Emoji.HotReload, MessageSeverity.Verbose);
188188
public static readonly MessageDescriptor FixBuildError = Create("Fix the error to continue or press Ctrl+C to exit.", Emoji.Watch, MessageSeverity.Warning);
189-
public static readonly MessageDescriptor WaitingForChanges = Create("Waiting for changes", Emoji.Watch, MessageSeverity.Verbose);
189+
public static readonly MessageDescriptor WaitingForChanges = Create("Waiting for changes", Emoji.Watch, MessageSeverity.Output);
190190
public static readonly MessageDescriptor LaunchedProcess = Create("Launched '{0}' with arguments '{1}': process id {2}", Emoji.Launch, MessageSeverity.Verbose);
191191
public static readonly MessageDescriptor HotReloadChangeHandled = Create("Hot reload change handled in {0}ms.", Emoji.HotReload, MessageSeverity.Verbose);
192192
public static readonly MessageDescriptor HotReloadSucceeded = Create(LogEvents.HotReloadSucceeded, Emoji.HotReload);

0 commit comments

Comments
 (0)