Skip to content

Commit

Permalink
Get SDK resolver interactivity level from SdkResolverContext (#2390)
Browse files Browse the repository at this point in the history
* Use reflection via an extension method to get the Interactive property

* Improve readability
  • Loading branch information
jeffkl authored and jainaashish committed Aug 22, 2018
1 parent d906ebb commit 62916a4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System.Reflection;
using Microsoft.Build.Framework;

namespace Microsoft.Build.NuGetSdkResolver
{
internal static class ExtensionMethods
{
// In MSBuild 15.9, the SdkResolverContext has an Interactive property. The value will be gotten through reflection so the MSBuild
// references do not need to be updated.
private static readonly PropertyInfo SdkResolverContextInteractivePropertyInfo = typeof(SdkResolverContext).GetRuntimeProperty("Interactive");

/// <summary>
/// Determines if the <see cref="SdkResolverContext"/> indicates if there should be no interactivity.
/// </summary>
/// <param name="context">A <see cref="SdkResolverContext"/> instance.</param>
/// <returns><code>true</code> if there should be no interactivity, otherwise <code>false</code>.</returns>
public static bool IsNonInteractive(this SdkResolverContext context)
{
// Determine if SdkResolverContext's Interactive property, defaulting to false
var interactive = (bool?) SdkResolverContextInteractivePropertyInfo?.GetValue(context) ?? false;

return !interactive;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public static SdkResult GetSdkResult(SdkReference sdk, object nuGetVersion, SdkR
try
{
var nugetSDKLogger = new NuGetSdkLogger(context.Logger, warnings, errors);
DefaultCredentialServiceUtility.SetupDefaultCredentialService(nugetSDKLogger, nonInteractive: true);
DefaultCredentialServiceUtility.SetupDefaultCredentialService(nugetSDKLogger, nonInteractive: context.IsNonInteractive());

// Asynchronously run the restore without a commit which find the package on configured feeds, download, and unzip it without generating any other files
// This must be run in its own task because legacy project system evaluates projects on the UI thread which can cause RunWithoutCommit() to deadlock
Expand Down

0 comments on commit 62916a4

Please sign in to comment.