Skip to content

Commit

Permalink
Simplify getting the deps.json stream
Browse files Browse the repository at this point in the history
  • Loading branch information
0xced committed Mar 12, 2024
1 parent e0d82b8 commit aef1992
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions tests/TestApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@

static IEnumerable<string> EnumerateDlls(string appPath)
{
var depsJsonFile = new FileInfo(Path.ChangeExtension(appPath, ".deps.json"));
using var depsJsonStream = depsJsonFile.Exists ? depsJsonFile.OpenRead() : GetEmbeddedJsonDepsStream(appPath);
using var depsJsonStream = GetJsonDepsStream(appPath);
using var reader = new DependencyContextJsonReader();
var dependencyContext = reader.Read(depsJsonStream);

Expand All @@ -49,7 +48,7 @@ static IEnumerable<string> EnumerateDlls(string appPath)
}

// See https://github.com/0xced/SingleFileAppDependencyContext
static Stream GetEmbeddedJsonDepsStream(string appPath)
static Stream GetJsonDepsStream(string appPath)
{
var depsJsonRegex = new Regex(@"DepsJson Offset:\[([0-9a-fA-F]+)\] Size\[([0-9a-fA-F]+)\]", RegexOptions.Compiled | RegexOptions.IgnoreCase);
var startInfo = new ProcessStartInfo(appPath)
Expand Down Expand Up @@ -94,5 +93,5 @@ static Stream GetEmbeddedJsonDepsStream(string appPath)
return appHostFile.CreateViewStream(depsJsonOffset.Value, depsJsonSize.Value, MemoryMappedFileAccess.Read);
}

throw new InvalidOperationException("The .deps.json location was not found in the AppHost logs");
return new FileStream(Path.ChangeExtension(appPath, ".deps.json"), FileMode.Open);
}

0 comments on commit aef1992

Please sign in to comment.