зеркало из
1
0
Форкнуть 0
Перейти к файлу
Dean Ellis 60fae1924e
[Microsoft.Android.Build.BaseTasks] retry when copying files (#245)
Context: https://github.com/dotnet/android/issues/9133
Context: https://learn.microsoft.com/visualstudio/msbuild/copy-task?view=vs-2022

We sometimes get collisions between the Design-Time-Build (or
AntiVirus) and our main build.  This can result in errors such as:

	Error (active)	XALNS7019	System.UnauthorizedAccessException: Access to the path 'D:\Projects\MauiApp2\obj\Debug\net9.0-android\android\assets\armeabi-v7a\MauiApp2.dll' is denied.
	   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
	   at System.IO.File.InternalDelete(String path, Boolean checkHost)
	   at Microsoft.Android.Build.Tasks.Files.CopyIfChanged(String source, String destination) in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/Files.cs:line 125
	   at Xamarin.Android.Tasks.MonoAndroidHelper.CopyAssemblyAndSymbols(String source, String destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs:line 344
	   at Xamarin.Android.Tasks.LinkAssembliesNoShrink.CopyIfChanged(ITaskItem source, ITaskItem destination) in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 161
	   at Xamarin.Android.Tasks.LinkAssembliesNoShrink.RunTask() in /Users/runner/work/1/s/xamarin-android/src/Xamarin.Android.Build.Tasks/Tasks/LinkAssembliesNoShrink.cs:line 76
	   at Microsoft.Android.Build.Tasks.AndroidTask.Execute() in /Users/runner/work/1/s/xamarin-android/external/xamarin-android-tools/src/Microsoft.Android.Build.BaseTasks/AndroidTask.cs:line 25	MauiApp2 (net9.0-android)	C:\Program Files\dotnet\packs\Microsoft.Android.Sdk.Windows\34.99.0-preview.6.340\tools\Xamarin.Android.Common.targets	1407

If we look at the [MSBuild `<Copy/>` task][0] we see that it has a
retry system in the cases of `UnauthorizedAccessException` or
`IOException` when the code is `ACCESS_DENIED` or
`ERROR_SHARING_VIOLATION`.  The `<Copy/>` task also has public
`Retries` and `RetryDelayMilliseconds` properties to control behavior.

Duplicate that kind of logic into our `Files.Copy*IfChanged()` helper
methods.  This should give our builds a bit more resiliency to these
kinds of issues.

Instead of adding new `Files.Copy*IfChanged()` method overloads which
accept "retries" and "retryDelay" parameters, we instead use
environment variables to allow overriding these values:

  * `DOTNET_ANDROID_FILE_WRITE_RETRY_ATTEMPTS`: The number of times
    to try to retry a copy operation; corresponds to the
    `Copy.Retries` MSBuild task property.

    The default value is 10.

  * `DOTNET_ANDROID_FILE_WRITE_RETRY_DELAY_MS`: The amount of time,
    in milliseconds, to delay between attempted copies; corresponds
    to the `Copy.RetryDelayMilliseconds` MSBuild task property.

    The default value is 1000 ms.

[0]: https://github.com/dotnet/msbuild/blob/main/src/Tasks/Copy.cs#L897
2024-10-22 11:57:55 -04:00
.vscode
Localize
build-tools/scripts Update README.md and build scripts (#238) 2024-06-13 14:19:49 -04:00
src [Microsoft.Android.Build.BaseTasks] retry when copying files (#245) 2024-10-22 11:57:55 -04:00
tests [Microsoft.Android.Build.BaseTasks] retry when copying files (#245) 2024-10-22 11:57:55 -04:00
tools/ls-jdks
.editorconfig
.gitattributes
.gitignore
CODE-OF-CONDUCT.md Update README.md and build scripts (#238) 2024-06-13 14:19:49 -04:00
Directory.Build.props
Directory.Build.targets
GitInfo.txt
LICENSE Update README.md and build scripts (#238) 2024-06-13 14:19:49 -04:00
Makefile Update README.md and build scripts (#238) 2024-06-13 14:19:49 -04:00
NuGet.config
README.md Update pipeline and pipeline info in README.md (#239) 2024-06-14 14:27:56 -04:00
SECURITY.md
Xamarin.Android.Tools.code-workspace
Xamarin.Android.Tools.sln
azure-pipelines.yaml [BaseTasks] Import Xamarin.Build.AsyncTask (#237) 2024-06-27 13:12:43 -04:00
global.json
nuget.version
product.snk

README.md

android-tools

Build Status

android-tools is a repo to easily share code between the xamarin-android repo and the .NET for Android commercial tooling, such as IDE extensions, without requiring that the IDE extensions submodule the entire android repo, which is gigantic.

Build Requirements

-android-tools requires .NET 6 or later.

Build Configuration

The default make all target accepts the following optional make(1) variables:

  • $(CONFIGURATION): The configuration to build. Possible values include Debug and Release. The default value is Debug.
  • $(V): Controls build verbosity. When set to a non-zero value, The build is built with /v:diag logging.

Build

To build android-tools:

dotnet build Xamarin.Android.Tools.sln

Alternatively run make:

make

Tests

To run the unit tests:

dotnet test tests/Xamarin.Android.Tools.AndroidSdk-Tests/Xamarin.Android.Tools.AndroidSdk-Tests.csproj -l "console;verbosity=detailed"

Build Output Directory Structure

There are two configurations, Debug and Release, controlled by the $(Configuration) MSBuild property or the $(CONFIGURATION) make variable.

The bin\$(Configuration) directory, e.g. bin\Debug, contains redistributable artifacts. The bin\Test$(Configuration) directory, e.g. bin\TestDebug, contains unit tests and related files.

  • bin\$(Configuration): redistributable build artifacts.
  • bin\Test$(Configuration): Unit tests and related files.

Distribution

Package versioning follows Semantic Versioning 2.0.0. The major version in the nuget.version file should be updated when a breaking change is introduced. The minor version should be updated when new functionality is added. The patch version will be automatically determined by the number of commits since the last version change.

Xamarin.Android.Tools.AndroidSdk nupkg files are produced for every build which occurrs on Azure Devops. To download one of these packages, navigate to the build you are interested in and click on the Artifacts button.

Alternatively, "unofficial" releases are currently hosted on the Xamarin.Android feed. Add the feed to your project's NuGet.config to reference these packages:

<configuration>
  <packageSources>
    <add key="Xamarin.Android" value="https://pkgs.dev.azure.com/xamarin/public/_packaging/Xamarin.Android/nuget/v3/index.json" />
  </packageSources>
</configuration>

Mailing Lists

To discuss this project, and participate in the design, we use the android-devel@lists.xamarin.com mailing list.

Coding Guidelines

We use Mono's Coding Guidelines.

Reporting Bugs

We use GitHub to track issues.