Skip to content

Commit

Permalink
Removed stderr logging code. Added more condition to intercept nuget.…
Browse files Browse the repository at this point in the history
…exe failed resources
  • Loading branch information
Fernando Aguilar committed Sep 21, 2022
1 parent e762dd0 commit bf29a7c
Showing 1 changed file with 4 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/NuGet.Clients/NuGet.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
using System.Net;
using System.Reflection;
using System.Text;
using System.Xml.Linq;
using Microsoft.Win32;
using NuGet.Common;
using NuGet.PackageManagement;
Expand Down Expand Up @@ -226,44 +225,27 @@ private void Initialize(CoreV2.NuGet.IFileSystem fileSystem, IConsole console)
}
}

private void LogToStderr(string message, ConsoleColor fontColor)
{
System.Console.ForegroundColor = fontColor;
System.Console.Error.WriteLine(message);
System.Console.ResetColor();

}

private Assembly CurrentDomain_ResourceResolve(object sender, ResolveEventArgs args)
{
LogToStderr($"****** Requesting resource: {args.Name}; who asks: {args.RequestingAssembly}; sender: {sender}; senderType: {sender?.GetType()}", ConsoleColor.Green);

Assembly returnedResource = null;
/*
AssemblyName requestedResource = new AssemblyName(args.Name);
if (args.RequestingAssembly.GetName().Name.EndsWith(".resources", StringComparison.OrdinalIgnoreCase) && requestedResource.Name.StartsWith("NuGet.CommandLine", StringComparison.OrdinalIgnoreCase) || requestedResource.Name.StartsWith("NuGet.Commands", StringComparison.OrdinalIgnoreCase))
{
returnedResource = GetNuGetResourcesAssembly(requestedResource.Name, args.RequestingAssembly.GetName().CultureInfo);
}
*/

if (!args.Name.StartsWith("NuGet.CommandLine", StringComparison.OrdinalIgnoreCase) && args.Name.StartsWith("NuGet", StringComparison.OrdinalIgnoreCase))
// We want to intercept NuGet.Resources resources and redirect it to nuget.exe assembly
if (!args.Name.StartsWith("NuGet.CommandLine", StringComparison.OrdinalIgnoreCase) && args.Name.StartsWith("NuGet", StringComparison.OrdinalIgnoreCase) && string.Equals("NuGet.Resources", args.RequestingAssembly.GetName().Name, StringComparison.OrdinalIgnoreCase))
{
ManifestResourceInfo resource = NuGetExeAssembly.GetManifestResourceInfo(args.Name);
if (resource != null)
{
returnedResource = LoadAssemblyFromEmbeddedResources(args.Name);
// Return nuget.exe assembly, since it contains the requested resource by nuget.restources assembly
returnedResource = NuGetExeAssembly;
}
}

LogToStderr($"++++++ Returned resource: '{returnedResource}'", ConsoleColor.Green);
return returnedResource;
}

// This method acts as a binding redirect
private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
LogToStderr($"****** Requesting assembly: {args.Name}; who asks: {args.RequestingAssembly}; sender: {sender}; senderType: {sender?.GetType()}", ConsoleColor.Red);
AssemblyName name = new AssemblyName(args.Name);
Assembly customLoadedAssembly = null;

Expand All @@ -280,8 +262,6 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a
customLoadedAssembly = GetNuGetResourcesAssembly(name.Name, name.CultureInfo);
}

LogToStderr($"+++++++++ Returning assembly: '{customLoadedAssembly}'", ConsoleColor.Red);

return customLoadedAssembly;
}

Expand Down

0 comments on commit bf29a7c

Please sign in to comment.