Skip to content

Commit 45c7a1b

Browse files
authored
Add telemetry for NUGET_USE_LEGACY_ASSET_TARGET_FALLBACK_DEPENDENCY_RESOLUTION (#7231)
1 parent 9131f71 commit 45c7a1b

2 files changed

Lines changed: 9 additions & 2 deletions

File tree

src/NuGet.Core/NuGet.Commands/RestoreCommand/RestoreCommand.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class RestoreCommand
4040
private readonly Dictionary<RestoreTargetGraph, Dictionary<string, LibraryIncludeFlags>> _includeFlagGraphs
4141
= new Dictionary<RestoreTargetGraph, Dictionary<string, LibraryIncludeFlags>>();
4242

43+
internal IEnvironmentVariableReader EnvironmentVariableReader { get; init; }
4344
public Guid ParentId { get; }
4445

4546
private const string ProjectRestoreInformation = nameof(ProjectRestoreInformation);
@@ -67,6 +68,7 @@ private readonly Dictionary<RestoreTargetGraph, Dictionary<string, LibraryInclud
6768
private const string UpdatedMSBuildFiles = nameof(UpdatedMSBuildFiles);
6869
private const string IsPackageInstallationTrigger = nameof(IsPackageInstallationTrigger);
6970
private const string UsesLegacyPackagesDirectory = nameof(UsesLegacyPackagesDirectory);
71+
private const string UsesLegacyAssetTargetFallback = nameof(UsesLegacyAssetTargetFallback);
7072

7173
// no-op data names
7274
private const string NoOpDuration = nameof(NoOpDuration);
@@ -173,6 +175,7 @@ public RestoreCommand(RestoreRequest request)
173175

174176
_isLockFileEnabled = PackagesLockFileUtilities.IsNuGetLockFileEnabled(_request.Project);
175177
_enableNewDependencyResolver = _request.Project.RuntimeGraph.Supports.Count == 0 && ShouldUseNewResolverWithLockFile(_isLockFileEnabled, _request.Project) && !_request.Project.RestoreMetadata.UseLegacyDependencyResolver;
178+
EnvironmentVariableReader = EnvironmentVariableWrapper.Instance;
176179
}
177180

178181
// Use the new resolver if lock files are not enabled, or if lock files are enabled and legacy projects or .NET 10 SDK is used.
@@ -384,6 +387,8 @@ private void InitializeTelemetry(TelemetryActivity telemetry, int httpSourcesCou
384387
telemetry.TelemetryEvent[NETSdkVersion] = _request.Project.RestoreSettings.SdkVersion;
385388
telemetry.TelemetryEvent[IsPackageInstallationTrigger] = !_request.IsRestoreOriginalAction;
386389
telemetry.TelemetryEvent[UsesLegacyPackagesDirectory] = !_request.IsLowercasePackagesDirectory;
390+
telemetry.TelemetryEvent[UsesLegacyAssetTargetFallback] = MSBuildStringUtility.IsTrue(EnvironmentVariableReader.GetEnvironmentVariable("NUGET_USE_LEGACY_ASSET_TARGET_FALLBACK_DEPENDENCY_RESOLUTION"));
391+
387392
_operationId = telemetry.OperationId;
388393

389394
var isCpvmEnabled = _request.Project.RestoreMetadata?.CentralPackageVersionsEnabled ?? false;

test/NuGet.Core.Tests/NuGet.Commands.Test/RestoreCommandTests/RestoreCommandTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3022,6 +3022,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
30223022
["Pruning.RemovablePackages.Count"] = value => value.Should().BeOfType<int>(),
30233023
["Pruning.Pruned.Direct.Count"] = value => value.Should().BeOfType<int>(),
30243024
["UsesLegacyPackagesDirectory"] = value => value.Should().Be(false),
3025+
["UsesLegacyAssetTargetFallback"] = value => value.Should().Be(false),
30253026
};
30263027

30273028
HashSet<string> actualProperties = new();
@@ -3134,7 +3135,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
31343135

31353136
var projectInformationEvent = telemetryEvents.Single(e => e.Name.Equals("ProjectRestoreInformation"));
31363137

3137-
projectInformationEvent.Count.Should().Be(40);
3138+
projectInformationEvent.Count.Should().Be(41);
31383139

31393140
projectInformationEvent["RestoreSuccess"].Should().Be(true);
31403141
projectInformationEvent["NoOpResult"].Should().Be(true);
@@ -3176,6 +3177,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
31763177
projectInformationEvent["Pruning.FrameworksUnsupported.Count"].Should().Be(1);
31773178
projectInformationEvent["Pruning.DefaultEnabled"].Should().Be(false);
31783179
projectInformationEvent["UsesLegacyPackagesDirectory"].Should().Be(false);
3180+
projectInformationEvent["UsesLegacyAssetTargetFallback"].Should().Be(false);
31793181
}
31803182

31813183
[Fact]
@@ -3233,7 +3235,7 @@ await SimpleTestPackageUtility.CreateFolderFeedV3Async(
32333235

32343236
var projectInformationEvent = telemetryEvents.Single(e => e.Name.Equals("ProjectRestoreInformation"));
32353237

3236-
projectInformationEvent.Count.Should().Be(48);
3238+
projectInformationEvent.Count.Should().Be(49);
32373239
projectInformationEvent["RestoreSuccess"].Should().Be(true);
32383240
projectInformationEvent["NoOpResult"].Should().Be(false);
32393241
projectInformationEvent["TotalUniquePackagesCount"].Should().Be(2);

0 commit comments

Comments
 (0)