Skip to content

Commit

Permalink
Avoid file locking to prevent conflicting with MSBuild
Browse files Browse the repository at this point in the history
  • Loading branch information
exyi committed Nov 22, 2022
1 parent 136d083 commit 1e86c74
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/native-lib-dotvvm-spy/AnalyzerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public static AnalyzerContext Get(int id)

public AnalyzerContext(string mainAssembly, string[] searchDirectories)
{
var main = new PEFile(mainAssembly);
var main = new PEFile(mainAssembly, StreamOptions);
var frameworkVersion = main.DetectTargetFrameworkId();
var resolver = new UniversalAssemblyResolver(main.FileName, false, frameworkVersion);
var resolver = new UniversalAssemblyResolver(main.FileName, false, frameworkVersion, streamOptions: StreamOptions);
foreach (var sd in searchDirectories)
resolver.AddSearchDirectory(sd);

Expand Down Expand Up @@ -71,4 +71,17 @@ public void Dispose()
states[Id] = null;
}
}

static AnalyzerContext()
{
// disable locking on Linux/Darwin to avoid blocking MSBuild
AppContext.SetSwitch("System.IO.DisableFileLocking", true);
}
// prefetch entire files on Windows to avoid locking
// on Linux/Darwin, we disable locking, so we can leave it on disk and avoid spending memory
private PEStreamOptions StreamOptions =>
System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)
? PEStreamOptions.PrefetchEntireImage
: PEStreamOptions.Default;

}

0 comments on commit 1e86c74

Please sign in to comment.