diff --git a/src/code/InternalHooks.cs b/src/code/InternalHooks.cs new file mode 100644 index 000000000..9b5ea0294 --- /dev/null +++ b/src/code/InternalHooks.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Reflection; + +namespace Microsoft.PowerShell.PSResourceGet.UtilClasses +{ + public class InternalHooks + { + internal static bool InvokedFromCompat; + + public static void SetTestHook(string property, object value) + { + var fieldInfo = typeof(InternalHooks).GetField(property, BindingFlags.Static | BindingFlags.NonPublic); + fieldInfo?.SetValue(null, value); + } + } +} \ No newline at end of file diff --git a/src/code/ServerFactory.cs b/src/code/ServerFactory.cs index 441e5eef4..8be08662e 100644 --- a/src/code/ServerFactory.cs +++ b/src/code/ServerFactory.cs @@ -25,7 +25,11 @@ static UserAgentInfo() private static string _psResourceGetVersion; private static string _distributionChannel; - internal static string UserAgentString => $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel}"; + internal static string UserAgentString() + { + string psGetCompat = InternalHooks.InvokedFromCompat ? "true" : "false"; + return $"PSResourceGet/{_psResourceGetVersion} PowerShell/{_psVersion} DistributionChannel/{_distributionChannel} PowerShellGetCompat/{psGetCompat}"; + } } internal class ServerFactory @@ -34,7 +38,7 @@ public static ServerApiCall GetServer(PSRepositoryInfo repository, PSCmdlet cmdl { PSRepositoryInfo.APIVersion repoApiVersion = repository.ApiVersion; ServerApiCall currentServer = null; - string userAgentString = UserAgentInfo.UserAgentString; + string userAgentString = UserAgentInfo.UserAgentString(); switch (repoApiVersion) {