Skip to content

Commit a230cc6

Browse files
committed
Merge branch 'stable'
* stable: (chocolateyGH-1949) Release mode - use entry assembly to check
2 parents 54ddf11 + ef3c6d7 commit a230cc6

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/chocolatey/infrastructure.app/ApplicationParameters.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,23 @@ public static class ApplicationParameters
3535
// always look at the official location of the machine installation
3636
public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
3737
public static readonly string LicensedAssemblyLocation = _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
38-
#else
38+
#elif DEBUG
3939
// Install location is choco.exe or chocolatey.dll
4040
public static readonly string InstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
41+
// when being used as a reference, start by looking next to Chocolatey, then in a subfolder.
42+
public static readonly string LicensedAssemblyLocation = _fileSystem.file_exists(_fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll")) ? _fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll") : _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
43+
#else
44+
// Install locations is chocolatey.dll or choco.exe - In Release mode
45+
// we might be testing on a server or in the local debugger. Either way,
46+
// start from the assembly location and if unfound, head to the machine
47+
// locations instead. This is a merge of official and Debug modes.
48+
public static readonly string InstallLocation = _fileSystem.file_exists(_fileSystem.combine_paths(_fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)), "chocolatey.dll")) ?
49+
_fileSystem.get_directory_name(Assembly.GetEntryAssembly().CodeBase.Replace("file:///", string.Empty)) :
50+
!string.IsNullOrWhiteSpace(System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName)) ?
51+
System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) :
52+
@"C:\ProgramData\Chocolatey"
53+
;
54+
4155
// when being used as a reference, start by looking next to Chocolatey, then in a subfolder.
4256
public static readonly string LicensedAssemblyLocation = _fileSystem.file_exists(_fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll")) ? _fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll") : _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
4357
#endif

src/chocolatey/infrastructure/adapters/Assembly.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,11 @@ public static IAssembly GetExecutingAssembly()
113113
public static IAssembly GetCallingAssembly()
114114
{
115115
return new Assembly(System.Reflection.Assembly.GetCallingAssembly());
116+
}
117+
118+
public static IAssembly GetEntryAssembly()
119+
{
120+
return new Assembly(System.Reflection.Assembly.GetEntryAssembly());
116121
}
117122

118123
public static IAssembly set_assembly(System.Reflection.Assembly value)

0 commit comments

Comments
 (0)