Skip to content

Commit

Permalink
Merge branch 'release/0.3.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
natemcmaster committed Dec 15, 2019
2 parents f15ce75 + c68b1c8 commit e5d74ec
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 11 deletions.
40 changes: 40 additions & 0 deletions samples/hot-reload/run.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
$ErrorActionPreference = 'Stop'

Push-Location $PSScriptRoot
try {
$publish_dir = "$PSScriptRoot/bin/plugins/TimestampedPlugin/"

function log {
Write-Host -NoNewline -ForegroundColor Yellow "run.ps1: "
Write-Host $args
}

function publish {
Write-Host ""
dotnet publish --no-restore TimestampedPlugin/ -o $publish_dir -nologo
Write-Host ""
}

log "Compiling apps"

& dotnet build HotReloadApp -nologo -clp:NoSummary
& publish

log "Use CTRL+C to exit"

$bg_args = @("run", "--no-build", "--project", "HotReloadApp", "$publish_dir/TimestampedPlugin.dll")
$host_process = Start-Process -NoNewWindow -FilePath dotnet -ArgumentList $bg_args
try {
while ($true) {
Start-Sleep 5
log "Rebuilding plugin..."
publish
}
}
finally {
$host_process.Kill()
}
}
finally {
Pop-Location
}
12 changes: 6 additions & 6 deletions src/Plugins/Loader/ManagedLoadContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public ManagedLoadContext(string mainAssemblyPath,
var resolvedPath = _dependencyResolver.ResolveAssemblyToPath(assemblyName);
if (!string.IsNullOrEmpty(resolvedPath) && File.Exists(resolvedPath))
{
return LoadFromAssemblyPath(resolvedPath);
return LoadAssemblyFromFilePath(resolvedPath);
}
#endif

Expand All @@ -120,7 +120,7 @@ public ManagedLoadContext(string mainAssemblyPath,
var resourcePath = Path.Combine(resourceRoot, assemblyName.CultureName, assemblyName.Name + ".dll");
if (File.Exists(resourcePath))
{
return LoadFromAssemblyPath(resourcePath);
return LoadAssemblyFromFilePath(resourcePath);
}
}

Expand All @@ -131,7 +131,7 @@ public ManagedLoadContext(string mainAssemblyPath,
{
if (SearchForLibrary(library, out var path) && path != null)
{
return LoadFromAssemblyPath(path);
return LoadAssemblyFromFilePath(path);
}
}
else
Expand All @@ -141,18 +141,18 @@ public ManagedLoadContext(string mainAssemblyPath,
var localFile = Path.Combine(_basePath, assemblyName.Name + ".dll");
if (File.Exists(localFile))
{
return LoadFromAssemblyPath(localFile);
return LoadAssemblyFromFilePath(localFile);
}
}

return null;
}

private new Assembly LoadFromAssemblyPath(string path)
public Assembly LoadAssemblyFromFilePath(string path)
{
if (!_loadInMemory)
{
return base.LoadFromAssemblyPath(path);
return LoadFromAssemblyPath(path);
}

using var file = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
Expand Down
10 changes: 5 additions & 5 deletions src/Plugins/PluginLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static PluginLoader CreateFromAssemblyFile(string assemblyFile, Action<Pl
}

private readonly PluginConfig _config;
private AssemblyLoadContext _context;
private ManagedLoadContext _context;
private readonly AssemblyLoadContextBuilder _contextBuilder;
private volatile bool _disposed;

Expand All @@ -163,7 +163,7 @@ public PluginLoader(PluginConfig config)
{
_config = config ?? throw new ArgumentNullException(nameof(config));
_contextBuilder = CreateLoadContextBuilder(config);
_context = _contextBuilder.Build();
_context = (ManagedLoadContext)_contextBuilder.Build();
#if FEATURE_UNLOAD
if (config.EnableHotReload)
{
Expand Down Expand Up @@ -210,7 +210,7 @@ public void Reload()
}

_context.Unload();
_context = _contextBuilder.Build();
_context = (ManagedLoadContext)_contextBuilder.Build();
GC.Collect();
GC.WaitForPendingFinalizers();
Reloaded?.Invoke(this, new PluginReloadedEventArgs(this));
Expand Down Expand Up @@ -255,7 +255,7 @@ private void OnFileChanged(object source, FileSystemEventArgs e)
public Assembly LoadDefaultAssembly()
{
EnsureNotDisposed();
return _context.LoadFromAssemblyPath(_config.MainAssemblyPath);
return _context.LoadAssemblyFromFilePath(_config.MainAssemblyPath);
}

/// <summary>
Expand All @@ -275,7 +275,7 @@ public Assembly LoadAssembly(AssemblyName assemblyName)
/// <param name="assemblyPath">The assembly path.</param>
/// <returns>The assembly.</returns>
public Assembly LoadAssemblyFromPath(string assemblyPath)
=> _context.LoadFromAssemblyPath(assemblyPath);
=> _context.LoadAssemblyFromFilePath(assemblyPath);

/// <summary>
/// Load an assembly by name.
Expand Down
4 changes: 4 additions & 0 deletions src/Plugins/releasenotes.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
Changes:
* Add an API to enable contextual reflection in .NET Core 3+ (see https://github.com/natemcmaster/DotNetCorePlugins/blob/v1.0.0/README.md#Reflection for details)
* Remove API that was made obsolete in 0.3.0
</PackageReleaseNotes>
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '0.3.2'">
Fixes:
* Fix issue preventing hot reload from working on Windows (#108)
</PackageReleaseNotes>
<PackageReleaseNotes Condition="'$(VersionPrefix)' == '0.3.1'">
Fixes:
Expand Down

0 comments on commit e5d74ec

Please sign in to comment.