Creating .NET MAUI Project sometimes causes error *.png is being used by another process #25374
+90
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #25207
Context
dotnet/android-tools#245
dotnet/android#9409
So there is a problem where the design time builds (DTB) of android sometimes lock files. This can happen when two processes try to write to the same file. This is not a great experience for our users as it just fails the build.
So lets try a few things to fix this.
$(IntermediateOutputPath)designtime
folder. This will keep the DTB files completely separate. This should prevent clashes.SkiaSharpTools.Save
method. This will catchUnauthorizedAccessException
exceptions as well as specificIOException
types (Access Denied and Sharing Violation). This will allow us to catch when this happens and retry the write. There is a small delay before attempting to write the file again.Note these code uses the Identical code as we are going to use in Android. We have introduced two new environment variables which can be used to control the new behavior.
DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS
. Integer, controls the number of times we try to write the file. The default is 10.DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS
. Integer, controls the delay in milliseconds between retry attempts. Default is 1000ms (or 1 second).