Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit 455db4e

Browse files
author
marksjac
committed
Updated plugin assembly search and load to resolve assembly binding issue at runtime.
1 parent 0a461fa commit 455db4e

File tree

6 files changed

+43
-142
lines changed

6 files changed

+43
-142
lines changed

AWSDeploymentAssistant/AWSDeploymentAssistant.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
<DesignTimeSharedInput>True</DesignTimeSharedInput>
116116
<DependentUpon>Settings.settings</DependentUpon>
117117
</Compile>
118-
<Compile Include="PluginUtil.cs" />
119118
<Compile Include="Request.cs" />
120119
</ItemGroup>
121120
<ItemGroup>

AWSDeploymentAssistant/App.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ or implied. See the License for the specific language governing permissions and
3838
</startup>
3939
<runtime>
4040
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
41-
<probing privatePath="plugins" />
41+
<probing privatePath="bin;bin\plugins" />
4242
</assemblyBinding>
4343
</runtime>
4444
<applicationSettings>

AWSDeploymentAssistant/Pipeline.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,9 @@ private void PopulateRequestWorkingDirectory()
144144

145145
private void RunPlugins()
146146
{
147-
DirectoryInfo taskDirectory = new DirectoryInfo(Program.TaskPluginFolderPath);
147+
DirectoryInfo pluginDirectory = new DirectoryInfo(Program.TaskPluginFolderPath);
148148

149-
var assemblyFiles = taskDirectory.GetFiles("*.dll", SearchOption.AllDirectories);
149+
var assemblyFiles = pluginDirectory.GetFiles("*.dll", SearchOption.AllDirectories);
150150

151151
Program.Logger.InfoFormat("Found [{0}] plugin assemblies.", assemblyFiles.Count());
152152

AWSDeploymentAssistant/PluginUtil.cs

Lines changed: 0 additions & 137 deletions
This file was deleted.

AWSDeploymentAssistant/Program.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@
1414
using System.Collections.Generic;
1515
using System.IO;
1616
using System.Reflection;
17+
using System.Linq;
1718

1819
namespace AWSDeploymentAssistant
1920
{
2021
public class Program
2122
{
23+
private static List<Assembly> _AssemblyCache;
24+
2225
public const string LogFolderPath = "C:\\temp\\AWS Development Tools\\EC2 Deployment Assistant\\logs";
2326
public const string TempFolderPath = "C:\\temp\\AWS Development Tools\\EC2 Deployment Assistant\\temp";
2427

@@ -32,6 +35,8 @@ public class Program
3235

3336
static Program()
3437
{
38+
Program._AssemblyCache = new List<Assembly>();
39+
3540
log4net.GlobalContext.Properties["LogPath"] = Program.LogFolderPath;
3641
Program.Logger = LogManager.GetLogger(Settings.Default.DefaultLoggerName);
3742

@@ -58,6 +63,8 @@ private static void Main(string[] args)
5863

5964
try
6065
{
66+
AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve;
67+
6168
if (Directory.Exists(Program.TempFolderPath) == false)
6269
{
6370
Directory.CreateDirectory(Program.TempFolderPath);
@@ -243,5 +250,37 @@ public static AWSCredentials GetAWSCredentials(string profileName)
243250
{
244251
return Amazon.Util.ProfileManager.GetAWSCredentials(profileName);
245252
}
253+
254+
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
255+
{
256+
if (Program._AssemblyCache.Count == 0)
257+
{
258+
Assembly executingAssembly = Assembly.GetExecutingAssembly();
259+
260+
FileInfo executingFile = new FileInfo(executingAssembly.Location);
261+
262+
DirectoryInfo applicationPath = executingFile.Directory;
263+
264+
var assemblyFiles = applicationPath.GetFiles("*.dll", SearchOption.AllDirectories);
265+
266+
foreach (FileInfo assemblyFile in assemblyFiles)
267+
{
268+
Assembly assembly = Assembly.LoadFile(assemblyFile.FullName);
269+
270+
if (Program._AssemblyCache.Contains(assembly) == false)
271+
{
272+
Program._AssemblyCache.Add(assembly);
273+
}
274+
}
275+
}
276+
277+
string searchTarget = args.Name.Substring(0, args.Name.IndexOf(","));
278+
279+
Assembly result = (from a in Program._AssemblyCache
280+
where string.Equals(a.FullName.Substring(0, a.FullName.IndexOf(",")), searchTarget, StringComparison.Ordinal)
281+
select a).SingleOrDefault();
282+
283+
return result;
284+
}
246285
}
247286
}

CodeDeployPlugin/CodeDeployPlugin.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
<Reference Include="System.Xml" />
6262
<Reference Include="YamlDotNet, Version=4.0.0.0, Culture=neutral, processorArchitecture=MSIL">
6363
<HintPath>..\packages\YamlDotNet.4.0.0\lib\net35\YamlDotNet.dll</HintPath>
64-
<Private>True</Private>
64+
<Private>False</Private>
6565
</Reference>
6666
</ItemGroup>
6767
<ItemGroup>

0 commit comments

Comments
 (0)