Skip to content

Commit

Permalink
Caching executing assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
Fernando Aguilar committed Sep 7, 2022
1 parent fddad28 commit fca1565
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/NuGet.Clients/NuGet.CommandLine/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ public class Program
private const string DotNetSetupRegistryKey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";
private const int Net462ReleasedVersion = 394802;

private static readonly string ThisExecutableName = typeof(Program).Assembly.GetName().Name;
internal static readonly Assembly NuGetExeAssembly = typeof(Program).Assembly;
private static readonly string ThisExecutableName = NuGetExeAssembly.GetName().Name;

[Import]
public HelpCommand HelpCommand { get; set; }
Expand Down Expand Up @@ -230,7 +231,7 @@ private Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs a

if (string.Equals(name.Name, ThisExecutableName, StringComparison.OrdinalIgnoreCase))
{
return typeof(Program).Assembly;
return NuGetExeAssembly;
}
// .NET Framework 4.x now triggers AssemblyResolve event for resource assemblies
// Catch this event for nuget.exe (NuGet.CommandLine) and NuGet.Command resource assemblies only
Expand Down Expand Up @@ -260,7 +261,7 @@ private static Assembly GetNuGetResourcesAssembly(string name, CultureInfo cultu
private static Assembly LoadAssemblyFromEmbeddedResources(string resourceName)
{
Assembly resourceAssembly = null;
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName))
using (var stream = NuGetExeAssembly.GetManifestResourceStream(resourceName))
{
if (stream == null)
{
Expand All @@ -278,7 +279,7 @@ private static Assembly LoadAssemblyFromEmbeddedResources(string resourceName)
[SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We don't want to block the exe from usage if anything failed")]
internal static void RemoveOldFile(CoreV2.NuGet.IFileSystem fileSystem)
{
var oldFile = typeof(Program).Assembly.Location + ".old";
var oldFile = NuGetExeAssembly.Location + ".old";
try
{
if (fileSystem.FileExists(oldFile))
Expand Down

0 comments on commit fca1565

Please sign in to comment.