Bug 9146 - The deployment stage of xbuild copies files using File.Copy without deleting them first, which can cause instability for in-use modules.
Summary: The deployment stage of xbuild copies files using File.Copy without deleting ...
Alias: None
Product: Tools
Classification: Mono
Component: xbuild ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2012-12-27 20:35 UTC by David McFarland
Modified: 2013-01-02 11:24 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

my local patch, don't commit (4.75 KB, patch)
2012-12-27 20:35 UTC, David McFarland

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description David McFarland 2012-12-27 20:35:12 UTC
Created attachment 3135 [details]
my local patch, don't commit

I have a bug for a specific manifestation of this: https://bugzilla.xamarin.com/show_bug.cgi?id=9124
And a WONTFIX for the actual modification of an in-use assembly: https://bugzilla.xamarin.com/show_bug.cgi?id=9128

When AssemblyBuilder writes an assembly, it calls File.Delete first (when running on mono).  That causes a new inode to be created for the file, instead of overwriting it when it's mapped by another process.

Microsoft.common.targets uses <Copy/> to copy .dlls to the output directory as part of the deploy step, so it doesn't get deleted like if it were written straight to the output directory.

I'm attaching my local patch which adds a flag to <Copy/> to delete the target before copying, and updates Microsoft.common.targets to use it.  It seems a bit hacky, but I'm not sure what the alternative is.
Comment 1 Alan McGovern 2013-01-02 11:13:14 UTC
We can't add that as it changes the public API of the assemblies. For our purposes, I don't see a problem with unconditionally deleting the target file before copying the new one over. I can't think of anything that would break.
Comment 2 Alan McGovern 2013-01-02 11:19:42 UTC
Implemented in git in both master and 2-10.
Comment 3 David McFarland 2013-01-02 11:21:47 UTC
Yeah, File.Copy isn't atomic anyway, so that seems like a reasonable solution.
Comment 4 Alan McGovern 2013-01-02 11:24:35 UTC
Thanks for the patch and report. The next release of mono should contain the fix. I'll take a quick look around to see if there are more places which might hit the same issue.