Skip to content

Commit

Permalink
Merge pull request #48 from ivanz/feature/parallel-execution-friendly…
Browse files Browse the repository at this point in the history
…-file-copy

Copy required assemblies without locking the source file. Should fix #43
  • Loading branch information
ivanz committed Mar 8, 2016
2 parents 2437131 + 8da8385 commit 91636c6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
1 change: 1 addition & 0 deletions Source/Machine.VSTestAdapter.VSIX/License.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
Copyright (c) 2012, 2013, 2014, 2015 Jonathan Wilkins
Copyright (c) 2016 Ivan Zlatev

This license governs use of the accompanying software. If you use the software, you
accept this license. If you do not accept the license, do not use the software.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,27 @@ private static AppDomain CreateAppDomain(string assemblyPath, string appName)

private static void CopyRequiredRuntimeDependencies(IEnumerable<Assembly> assemblies, string destination)
{
foreach (Assembly assembly in assemblies)
{
foreach (Assembly assembly in assemblies) {
string assemblyLocation = assembly.Location;
string assemblyName = Path.GetFileName(assemblyLocation);
string assemblyFileDestination = Path.Combine(destination, assemblyName);
File.Copy(assemblyLocation, assemblyFileDestination, true);
if (!File.Exists(assemblyFileDestination))
CopyWithoutLockingSourceFile(assemblyLocation, assemblyFileDestination);
}
}

private static void CopyWithoutLockingSourceFile(string sourceFile, string destinationFile)
{
const int BUFFER_SIZE = 10 * 1024;

using (FileStream inputFile = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read, BUFFER_SIZE))
using (FileStream outputFile = new FileStream(destinationFile, FileMode.Create, FileAccess.ReadWrite, FileShare.None, BUFFER_SIZE)) {
byte[] buffer = new byte[BUFFER_SIZE];
int bytes;

while ((bytes = inputFile.Read(buffer, 0, buffer.Length)) > 0) {
outputFile.Write(buffer, 0, bytes);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
environment:
nuget_version: '2.0.0-beta1'
nuget_version: '2.0.0-beta2'
vsix_version: '2.0.0'
assembly_version: '2.0.0'

Expand Down

0 comments on commit 91636c6

Please sign in to comment.