Skip to content

Commit 29b75f1

Browse files
authored
Fix "The process cannot access the file" error after a failed build (#1663)
* enforce MSBuild to never used shared compilation and start more than one process by doing that we lower the chances for getting "file in use" exception after re-running a failed build script * add comments
1 parent 174601c commit 29b75f1

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/dotnet.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,14 +277,19 @@ def restore(self,
277277
project.
278278
279279
Keyword arguments:
280-
packages_path -- The directory to restore packages to.
280+
packages_path -- The directory to restore packages to.
281+
MSBuild arguments used to avoid "process cannot access the file":
282+
/p:UseSharedCompilation=false -- disable shared compilation
283+
/p:BuildInParallel=false -- disable parallel builds
284+
/m:1 -- don't spawn more than a single process
281285
'''
282286
if not packages_path:
283287
raise TypeError('Unspecified packages directory.')
284288
cmdline = [
285289
'dotnet', 'restore',
286290
self.csproj_file,
287-
'--packages', packages_path
291+
'--packages', packages_path,
292+
'/p:UseSharedCompilation=false', '/p:BuildInParallel=false', '/m:1',
288293
]
289294

290295
if runtime_identifier:
@@ -309,6 +314,7 @@ def build(self,
309314
'--configuration', configuration,
310315
'--no-restore',
311316
"/p:NuGetPackageRoot={}".format(packages_path),
317+
'/p:UseSharedCompilation=false', '/p:BuildInParallel=false', '/m:1',
312318
]
313319

314320
if output_to_bindir:
@@ -332,6 +338,7 @@ def build(self,
332338
'--framework', target_framework_moniker,
333339
'--no-restore',
334340
"/p:NuGetPackageRoot={}".format(packages_path),
341+
'/p:UseSharedCompilation=false', '/p:BuildInParallel=false', '/m:1',
335342
]
336343

337344
if output_to_bindir:
@@ -402,7 +409,8 @@ def publish(self,
402409
self.csproj_file,
403410
'--configuration', configuration,
404411
'--output', output_dir,
405-
"/p:NuGetPackageRoot={}".format(packages_path)
412+
"/p:NuGetPackageRoot={}".format(packages_path),
413+
'/p:UseSharedCompilation=false', '/p:BuildInParallel=false', '/m:1'
406414
]
407415
if runtime_identifier:
408416
cmdline += ['--runtime', runtime_identifier]

0 commit comments

Comments
 (0)