From 8af91df02ca4eef7db144c1d1420d2b851e4027d Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 21:42:45 +1100 Subject: [PATCH 1/6] Inline private method This was only called in one place and the indirection doesn't add anything. --- .../VS/Build/LanguageServiceErrorListProvider.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs index 2f0b6c1fe0..7c62e26e01 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs @@ -47,15 +47,10 @@ public void ResumeRefresh() { } - public Task AddMessageAsync(TargetGeneratedError error) + public async Task AddMessageAsync(TargetGeneratedError error) { Requires.NotNull(error); - return AddMessageCoreAsync(error); - } - - private async Task AddMessageCoreAsync(TargetGeneratedError error) - { // We only want to pass compiler, analyzers, etc to the language // service, so we skip tasks that do not have a code if (!TryExtractErrorListDetails(error.BuildEventArgs, out ErrorListDetails details) || string.IsNullOrEmpty(details.Code)) From 88010af2d7f5c7a13be48c629fa42e80b4656055 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 21:43:20 +1100 Subject: [PATCH 2/6] Fix docs and null annotation --- .../VS/Build/LanguageServiceErrorListProvider.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs index 7c62e26e01..3a4db2b620 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/Build/LanguageServiceErrorListProvider.cs @@ -116,9 +116,9 @@ await _workspaceWriter.WriteAsync(workspace => /// /// Attempts to extract the details required by the VS Error List from an MSBuild build event. /// - /// The build event. May be null. - /// The extracted details, or if was or of an unrecognized type. - internal static bool TryExtractErrorListDetails(BuildEventArgs eventArgs, out ErrorListDetails result) + /// The build event. + /// The extracted details, or if was or of an unrecognized type. + internal static bool TryExtractErrorListDetails(BuildEventArgs? eventArgs, out ErrorListDetails result) { if (eventArgs is BuildErrorEventArgs errorMessage) { From 3123c4b05279955e8456a0ba5fc8686ca947e5c9 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 21:46:45 +1100 Subject: [PATCH 3/6] Telemetry values can be null We have some APIs that wrap telemetry operations, and they were imposing an artificial restriction on telemetry property values. A null value is perfectly valid. --- .../VS/TempPE/DesignTimeInputsCompiler.cs | 22 +++++++++--------- .../VS/UpToDate/BuildUpToDateCheck.Log.cs | 16 ++++++------- .../Telemetry/DesignTimeTelemetryLogger.cs | 8 +++---- .../PackageRestoreCycleDetector.cs | 8 +++---- .../Telemetry/SdkVersionReporter.cs | 7 +++--- .../Telemetry/ITelemetryOperation.cs | 2 +- .../Telemetry/ITelemetryService.cs | 8 ++----- .../Telemetry/ManagedTelemetryService.cs | 11 ++++----- .../Mocks/ITelemetryServiceFactory.cs | 4 ++-- .../Telemetry/ManagedTelemetryServiceTests.cs | 23 ++++++++----------- 10 files changed, 50 insertions(+), 59 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs index aa49ec9303..ac32b78690 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs @@ -162,13 +162,13 @@ private Task ProcessCompileQueueAsync(CancellationToken token) void LogTelemetry(bool cancelled) { compileStopWatch!.Stop(); - _telemetryService.PostProperties(TelemetryEventName.TempPEProcessQueue, new[] - { - ( TelemetryPropertyName.TempPE.CompileCount, (object)compileCount), - ( TelemetryPropertyName.TempPE.InitialQueueLength, initialQueueLength), - ( TelemetryPropertyName.TempPE.CompileWasCancelled, cancelled), - ( TelemetryPropertyName.TempPE.CompileDuration, compileStopWatch.ElapsedMilliseconds) - }); + _telemetryService.PostProperties(TelemetryEventName.TempPEProcessQueue, + [ + (TelemetryPropertyName.TempPE.CompileCount, compileCount), + (TelemetryPropertyName.TempPE.InitialQueueLength, initialQueueLength), + (TelemetryPropertyName.TempPE.CompileWasCancelled, cancelled), + (TelemetryPropertyName.TempPE.CompileDuration, compileStopWatch.ElapsedMilliseconds) + ]); } } @@ -202,10 +202,10 @@ public async Task BuildDesignTimeOutputAsync(string relativeFileName, st if (compiled) { - _telemetryService.PostProperties(TelemetryEventName.TempPECompileOnDemand, new[] - { - ( TelemetryPropertyName.TempPE.InitialQueueLength, (object)initialQueueLength) - }); + _telemetryService.PostProperties(TelemetryEventName.TempPECompileOnDemand, + [ + (TelemetryPropertyName.TempPE.InitialQueueLength, initialQueueLength) + ]); } return $@" diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/BuildUpToDateCheck.Log.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/BuildUpToDateCheck.Log.cs index 43e8988838..2cd8514f1c 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/BuildUpToDateCheck.Log.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/UpToDate/BuildUpToDateCheck.Log.cs @@ -199,9 +199,9 @@ public bool Fail(string reason, string resourceName, params object[] values) logLevel: Level); // Send telemetry. - _telemetryService?.PostProperties(TelemetryEventName.UpToDateCheckFail, new[] - { - (TelemetryPropertyName.UpToDateCheck.FailReason, (object)reason), + _telemetryService?.PostProperties(TelemetryEventName.UpToDateCheckFail, + [ + (TelemetryPropertyName.UpToDateCheck.FailReason, reason), (TelemetryPropertyName.UpToDateCheck.DurationMillis, _stopwatch.Elapsed.TotalMilliseconds), (TelemetryPropertyName.UpToDateCheck.WaitDurationMillis, _waitTime.TotalMilliseconds), (TelemetryPropertyName.UpToDateCheck.FileCount, _timestampCache.Count), @@ -211,7 +211,7 @@ public bool Fail(string reason, string resourceName, params object[] values) (TelemetryPropertyName.UpToDateCheck.CheckNumber, _checkNumber), (TelemetryPropertyName.UpToDateCheck.IgnoreKinds, _ignoreKinds ?? ""), (TelemetryPropertyName.UpToDateCheck.AccelerationResult, FileSystemOperations.AccelerationResult) - }); + ]); // Remember the failure reason and description for use in IncrementalBuildFailureDetector. // First, ensure times are converted to local time (in case logging is not enabled). @@ -245,9 +245,9 @@ public void UpToDate(int copyCount) logLevel: Level); // Send telemetry. - _telemetryService?.PostProperties(TelemetryEventName.UpToDateCheckSuccess, new[] - { - (TelemetryPropertyName.UpToDateCheck.DurationMillis, (object)_stopwatch.Elapsed.TotalMilliseconds), + _telemetryService?.PostProperties(TelemetryEventName.UpToDateCheckSuccess, + [ + (TelemetryPropertyName.UpToDateCheck.DurationMillis, _stopwatch.Elapsed.TotalMilliseconds), (TelemetryPropertyName.UpToDateCheck.WaitDurationMillis, _waitTime.TotalMilliseconds), (TelemetryPropertyName.UpToDateCheck.FileCount, _timestampCache.Count), (TelemetryPropertyName.UpToDateCheck.ConfigurationCount, _upToDateCheckConfiguredInput.ImplicitInputs.Length), @@ -257,7 +257,7 @@ public void UpToDate(int copyCount) (TelemetryPropertyName.UpToDateCheck.IgnoreKinds, _ignoreKinds ?? ""), (TelemetryPropertyName.UpToDateCheck.AccelerationResult, FileSystemOperations.AccelerationResult), (TelemetryPropertyName.UpToDateCheck.AcceleratedCopyCount, copyCount) - }); + ]); Info(nameof(VSResources.FUTD_UpToDate)); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Telemetry/DesignTimeTelemetryLogger.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Telemetry/DesignTimeTelemetryLogger.cs index e01d528d52..fce866989e 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Telemetry/DesignTimeTelemetryLogger.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/Telemetry/DesignTimeTelemetryLogger.cs @@ -67,11 +67,11 @@ public void Shutdown() string targetResults = builder.ToStringAndFree(); - _telemetryService.PostProperties(TelemetryEventName.DesignTimeBuildComplete, new[] - { - (TelemetryPropertyName.DesignTimeBuildComplete.Succeeded, (object)_succeeded), + _telemetryService.PostProperties(TelemetryEventName.DesignTimeBuildComplete, + [ + (TelemetryPropertyName.DesignTimeBuildComplete.Succeeded, _succeeded), (TelemetryPropertyName.DesignTimeBuildComplete.Targets, targetResults) - }); + ]); } } } diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/PackageRestore/PackageRestoreCycleDetector.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/PackageRestore/PackageRestoreCycleDetector.cs index 521730709b..2fd8d761d3 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/PackageRestore/PackageRestoreCycleDetector.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/PackageRestore/PackageRestoreCycleDetector.cs @@ -120,12 +120,12 @@ async Task OnCycleDetectedAsync() _nuGetRestoreCyclesDetected++; // Send telemetry. - _telemetryService.PostProperties(TelemetryEventName.NuGetRestoreCycleDetected, new[] - { - (TelemetryPropertyName.NuGetRestoreCycleDetected.RestoreDurationMillis, (object)_stopwatch.Elapsed.TotalMilliseconds), + _telemetryService.PostProperties(TelemetryEventName.NuGetRestoreCycleDetected, + [ + (TelemetryPropertyName.NuGetRestoreCycleDetected.RestoreDurationMillis, _stopwatch.Elapsed.TotalMilliseconds), (TelemetryPropertyName.NuGetRestoreCycleDetected.RestoreSuccesses, _nuGetRestoreSuccesses), (TelemetryPropertyName.NuGetRestoreCycleDetected.RestoreCyclesDetected, _nuGetRestoreCyclesDetected) - }); + ]); // Notify the user. await _userNotificationService.ShowErrorAsync( diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Telemetry/SdkVersionReporter.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Telemetry/SdkVersionReporter.cs index a3632ead7b..8126baa0c9 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Telemetry/SdkVersionReporter.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/ProjectSystem/Telemetry/SdkVersionReporter.cs @@ -46,11 +46,10 @@ public Task LoadAsync() { _telemetryService.PostProperties( TelemetryEventName.SDKVersion, - new[] - { - (TelemetryPropertyName.SDKVersion.Project, (object)projectGuid.ToString()), + [ + (TelemetryPropertyName.SDKVersion.Project, projectGuid.ToString()), (TelemetryPropertyName.SDKVersion.NETCoreSDKVersion, version) - }); + ]); } }, unconfiguredProject: _projectVsServices.Project); diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryOperation.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryOperation.cs index 6963cc1202..35cc5e25c0 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryOperation.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryOperation.cs @@ -27,7 +27,7 @@ internal interface ITelemetryOperation : IDisposable /// /// is contains no elements. /// - void SetProperties(IEnumerable<(string propertyName, object propertyValue)> properties); + void SetProperties(IEnumerable<(string propertyName, object? propertyValue)> properties); /// /// Ends the operation and reports the result. diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryService.cs index 0abd49b021..38e083813d 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ITelemetryService.cs @@ -40,10 +40,6 @@ internal interface ITelemetryService /// -or- /// /// is . - /// - /// -or- - /// - /// is . /// /// /// is an empty string (""). @@ -52,7 +48,7 @@ internal interface ITelemetryService /// /// is an empty string (""). /// - void PostProperty(string eventName, string propertyName, object propertyValue); + void PostProperty(string eventName, string propertyName, object? propertyValue); /// /// Posts an event with the specified event name and properties with the @@ -78,7 +74,7 @@ internal interface ITelemetryService /// /// is contains no elements. /// - void PostProperties(string eventName, IEnumerable<(string propertyName, object propertyValue)> properties); + void PostProperties(string eventName, IEnumerable<(string propertyName, object? propertyValue)> properties); /// /// Begins an operation with a recorded duration. Consumers must call diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs index 3173338f3f..ab1e262c08 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs @@ -20,11 +20,10 @@ public void PostEvent(string eventName) PostTelemetryEvent(new TelemetryEvent(eventName)); } - public void PostProperty(string eventName, string propertyName, object propertyValue) + public void PostProperty(string eventName, string propertyName, object? propertyValue) { Requires.NotNullOrEmpty(eventName); Requires.NotNullOrEmpty(propertyName); - Requires.NotNull(propertyValue); TelemetryEvent telemetryEvent = new(eventName); telemetryEvent.Properties.Add(propertyName, propertyValue); @@ -32,7 +31,7 @@ public void PostProperty(string eventName, string propertyName, object propertyV PostTelemetryEvent(telemetryEvent); } - public void PostProperties(string eventName, IEnumerable<(string propertyName, object propertyValue)> properties) + public void PostProperties(string eventName, IEnumerable<(string propertyName, object? propertyValue)> properties) { Requires.NotNullOrEmpty(eventName); Requires.NotNullOrEmpty(properties); @@ -43,9 +42,9 @@ public void PostProperties(string eventName, IEnumerable<(string propertyName, o PostTelemetryEvent(telemetryEvent); } - private static void AddPropertiesToEvent(IEnumerable<(string propertyName, object propertyValue)> properties, TelemetryEvent telemetryEvent) + private static void AddPropertiesToEvent(IEnumerable<(string propertyName, object? propertyValue)> properties, TelemetryEvent telemetryEvent) { - foreach ((string propertyName, object propertyValue) in properties) + foreach ((string propertyName, object? propertyValue) in properties) { if (propertyValue is ComplexPropertyValue complexProperty) { @@ -125,7 +124,7 @@ public void End(TelemetryResult result) _scope.End(result); } - public void SetProperties(IEnumerable<(string propertyName, object propertyValue)> properties) + public void SetProperties(IEnumerable<(string propertyName, object? propertyValue)> properties) { Requires.NotNullOrEmpty(properties); diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/ITelemetryServiceFactory.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/ITelemetryServiceFactory.cs index 022a88a5a9..bfb95dfef3 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/ITelemetryServiceFactory.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Mocks/ITelemetryServiceFactory.cs @@ -35,7 +35,7 @@ public static ITelemetryService Create(TelemetryParameters callParameters) }; }); - telemetryService.Setup(t => t.PostProperties(It.IsAny(), It.IsAny>())) + telemetryService.Setup(t => t.PostProperties(It.IsAny(), It.IsAny>())) .Callback((string e, IEnumerable<(string propertyName, object propertyValue)> p) => { callParameters.EventName = e; @@ -73,7 +73,7 @@ public static ITelemetryService Create(Action onTelemetryLo onTelemetryLogged(callParameters); }); - telemetryService.Setup(t => t.PostProperties(It.IsAny(), It.IsAny>())) + telemetryService.Setup(t => t.PostProperties(It.IsAny(), It.IsAny>())) .Callback((string e, IEnumerable<(string propertyName, object propertyValue)> p) => { var callParameters = new TelemetryParameters diff --git a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Telemetry/ManagedTelemetryServiceTests.cs b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Telemetry/ManagedTelemetryServiceTests.cs index ed49d337a1..2bff3f3c1d 100644 --- a/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Telemetry/ManagedTelemetryServiceTests.cs +++ b/tests/Microsoft.VisualStudio.ProjectSystem.Managed.UnitTests/Telemetry/ManagedTelemetryServiceTests.cs @@ -73,14 +73,11 @@ public void PostProperty_EmptyAsPropertyName_ThrowArgument() } [Fact] - public void PostProperty_NullAsPropertyValue_ThrowArgumentNull() + public void PostProperty_NullAsPropertyValue() { var service = CreateInstance(); - Assert.Throws("propertyValue", () => - { - service.PostProperty("event1", "propName", null!); - }); + service.PostProperty("vs/projectsystem/managed/test", "vs.projectsystem.managed.test", null); } [Fact] @@ -90,7 +87,7 @@ public void PostProperties_NullAsEventName_ThrowArgumentNull() Assert.Throws("eventName", () => { - service.PostProperties(null!, new[] { ("propertyName", (object)"propertyValue") }); + service.PostProperties(null!, [("propertyName", "propertyValue")]); }); } @@ -101,7 +98,7 @@ public void PostProperties_EmptyAsEventName_ThrowArgument() Assert.Throws("eventName", () => { - service.PostProperties(string.Empty, new[] { ("propertyName", (object)"propertyValue") }); + service.PostProperties(string.Empty, [("propertyName", "propertyValue")]); }); } @@ -123,7 +120,7 @@ public void PostProperties_EmptyProperties_ThrowArgument() Assert.Throws("properties", () => { - service.PostProperties("event1", Enumerable.Empty<(string propertyName, object propertyValue)>()); + service.PostProperties("event1", []); }); } @@ -136,7 +133,7 @@ public void PostEvent_SendsTelemetryEvent() service.PostEvent(TelemetryEventName.UpToDateCheckSuccess); Assert.NotNull(result); - Assert.Equal(TelemetryEventName.UpToDateCheckSuccess, result!.Name); + Assert.Equal(TelemetryEventName.UpToDateCheckSuccess, result.Name); } [Fact] @@ -158,11 +155,11 @@ public void PostProperties_SendsTelemetryEventWithProperties() TelemetryEvent? result = null; var service = CreateInstance((e) => { result = e; }); - service.PostProperties(TelemetryEventName.DesignTimeBuildComplete, new[] - { - (TelemetryPropertyName.DesignTimeBuildComplete.Succeeded, (object)true), + service.PostProperties(TelemetryEventName.DesignTimeBuildComplete, + [ + (TelemetryPropertyName.DesignTimeBuildComplete.Succeeded, true), (TelemetryPropertyName.DesignTimeBuildComplete.Targets, "Compile") - }); + ]); Assert.NotNull(result); Assert.Equal(TelemetryEventName.DesignTimeBuildComplete, result.Name); From 9c07ef50ed6fed2b907a852f989b6b6d60783518 Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 21:47:38 +1100 Subject: [PATCH 4/6] Formatting --- .../Telemetry/ManagedTelemetryService.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs index ab1e262c08..7eb10f4c11 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs @@ -62,7 +62,7 @@ private void PostTelemetryEvent(TelemetryEvent telemetryEvent) #if DEBUG Assumes.True(telemetryEvent.Name.StartsWith(EventNamePrefix, StringComparisons.TelemetryEventNames)); - foreach (string propertyName in telemetryEvent.Properties.Keys) + foreach ((string propertyName, _) in telemetryEvent.Properties) { Assumes.True(propertyName.StartsWith(PropertyNamePrefix, StringComparisons.TelemetryEventNames)); } @@ -79,11 +79,11 @@ protected virtual void PostEventToSession(TelemetryEvent telemetryEvent) public ITelemetryOperation BeginOperation(string eventName) { Requires.NotNullOrEmpty(eventName); - + #if DEBUG Assumes.True(eventName.StartsWith(EventNamePrefix, StringComparisons.TelemetryEventNames)); #endif - return new TelemetryOperation(TelemetryService.DefaultSession.StartOperation(eventName)); + return new TelemetryOperation(TelemetryService.DefaultSession.StartOperation(eventName)); } public string HashValue(string value) From 7035fbb6e5490c4a35068f402c9373c1c9f4eaed Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 21:53:02 +1100 Subject: [PATCH 5/6] Use raw string --- .../VS/TempPE/DesignTimeInputsCompiler.cs | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs index ac32b78690..8b02723049 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed.VS/ProjectSystem/VS/TempPE/DesignTimeInputsCompiler.cs @@ -208,16 +208,18 @@ public async Task BuildDesignTimeOutputAsync(string relativeFileName, st ]); } - return $@" - - -"; + return $""" + + + + + """; } private async Task CompileDesignTimeInputAsync(IWorkspaceProjectContext context, string designTimeInput, string outputFileName, ImmutableHashSet sharedInputs, bool ignoreFileWriteTime, CancellationToken token = default) From 163aa88d9c55aedfdcf101f2f287d7d5e12ba4df Mon Sep 17 00:00:00 2001 From: Drew Noakes Date: Mon, 11 Nov 2024 22:12:36 +1100 Subject: [PATCH 6/6] Use newer SHA256 API for .NET 8 --- .../Telemetry/ManagedTelemetryService.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs index 7eb10f4c11..919e63c879 100644 --- a/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs +++ b/src/Microsoft.VisualStudio.ProjectSystem.Managed/Telemetry/ManagedTelemetryService.cs @@ -95,8 +95,15 @@ public string HashValue(string value) } byte[] inputBytes = Encoding.UTF8.GetBytes(value); + +#if NET8_0_OR_GREATER + byte[] hash = SHA256.HashData(inputBytes); +#else using var cryptoServiceProvider = SHA256.Create(); - return BitConverter.ToString(cryptoServiceProvider.ComputeHash(inputBytes)); + byte[] hash = cryptoServiceProvider.ComputeHash(inputBytes); +#endif + + return BitConverter.ToString(hash); } private class TelemetryOperation : ITelemetryOperation