Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] create xamarin-android-tools.override.props #8145

Closed

Conversation

jonathanpeppers
Copy link
Member

If you installed the android workload via:

dotnet workload install android --skip-sign-check \
    --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/net8.0.json \
    --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json \
    --source https://api.nuget.org/v3/index.json

dotnet new android & dotnet build succeeds.

But MSBuild.exe fails with:

D:\src\dotnet-sdk-8.0.100-preview.6.23318.1-win-x64\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.6.323\tools\Xamarin.Android.EmbeddedResource.targets(39,5): error XARLP7028: System.IO.FileNotFoundException: Could not load file or assembly 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' or one of its dependencies. The system cannot find the file specified.
File name: 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc'
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(IDictionary`2 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments, ICollection`1 proguardConfigFiles)
at Xamarin.Android.Tasks.ResolveLibraryProjectImports.RunTask()
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
WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

It turns out that for references to libZipSharp.dll:

  • Microsoft.Android.Build.BaseTasks.dll references 2.1.0.0
  • Xamarin.Android.Build.Tasks.dll references 3.0.0.0

However, this appears to already be solved in the 34.0.0-preview.6.355 version of the android workload. It is broken in 34.0.0-preview.6.323.

In that time window, we updated $(LibZipSharpVersion) in xamarin/xamarin-android, but not yet bumped to the latest xamarin/xamarin-android-tools:

f1d5918

To solve this issue, we can use the extension points we added to:

dotnet/android-tools@34e98e2

And import xamarin-android's Directory.Build.props from xamarin-android-tools.override.props. With this change in place, I can set the value of $(LibZipSharpVersion) to any value and the value from xamarin-android overrides it.

This probably slipped through because we dropped the "classic" Xamarin.Android test suite that used .NET framework MSBuild on Windows. All tests now use dotnet build, so we need to add something to test MSBuild.exe?

@dellis1972
Copy link
Contributor

So does VS not use dotnet build then?

@jonathanpeppers
Copy link
Member Author

No VS doesn't use dotnet build at all, VS still uses:

C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\MSBuild.exe

@dellis1972
Copy link
Contributor

No VS doesn't use dotnet build at all, VS still uses:

C:\Program Files\Microsoft Visual Studio\2022\Preview\MSBuild\Current\Bin\MSBuild.exe

Hmm, ok so we probably should put back in some fake "IDE" style tests.

If you installed the `android` workload via:

    dotnet workload install android --skip-sign-check \
        --from-rollback-file https://maui.blob.core.windows.net/metadata/rollbacks/net8.0.json \
        --source https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json \
        --source https://api.nuget.org/v3/index.json

`dotnet new android` & `dotnet build` succeeds.

But `MSBuild.exe` fails with:

    D:\src\dotnet-sdk-8.0.100-preview.6.23318.1-win-x64\packs\Microsoft.Android.Sdk.Windows\34.0.0-preview.6.323\tools\Xamarin.Android.EmbeddedResource.targets(39,5): error XARLP7028: System.IO.FileNotFoundException: Could not load file or assembly 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' or one of its dependencies. The system cannot find the file specified.
    File name: 'libZipSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc'
    at Xamarin.Android.Tasks.ResolveLibraryProjectImports.Extract(IDictionary`2 jars, ICollection`1 resolvedResourceDirectories, ICollection`1 resolvedAssetDirectories, ICollection`1 resolvedEnvironments, ICollection`1 proguardConfigFiles)
    at Xamarin.Android.Tasks.ResolveLibraryProjectImports.RunTask()
    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
    WRN: Assembly binding logging is turned OFF.
    To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
    Note: There is some performance penalty associated with assembly bind failure logging.
    To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].

It turns out that for references to `libZipSharp.dll`:

* `Microsoft.Android.Build.BaseTasks.dll` references 2.1.0.0
* `Xamarin.Android.Build.Tasks.dll` references 3.0.0.0

However, this appears to already be solved in the 34.0.0-preview.6.355
version of the `android` workload. It is broken in
`34.0.0-preview.6.323`.

In that time window, we updated `$(LibZipSharpVersion)` in
xamarin/xamarin-android, but not yet bumped to the latest
xamarin/xamarin-android-tools:

dotnet@f1d5918

To solve this issue, we can use the extension points we added to:

dotnet/android-tools@34e98e2

And import xamarin-android's `Directory.Build.props` from
`xamarin-android-tools.override.props`. With this change in place, I can
set the value of `$(LibZipSharpVersion)` to any value and the value from
xamarin-android overrides it.

This probably slipped through because we dropped the "classic"
Xamarin.Android test suite that used .NET framework MSBuild on Windows.
All tests now use `dotnet build`.

I added a test that builds an Android project in Debug & Release with
`MSBuild.exe`, and updated Xamarin.ProjectTools to support doing this.
@@ -33,7 +33,6 @@ public abstract class XamarinProject
public string GlobalPackagesFolder { get; set; } = FileSystemUtils.FindNugetGlobalPackageFolder ();
public IList<string> ExtraNuGetConfigSources { get; set; } = new List<string> ();

public virtual bool ShouldRestorePackageReferences => PackageReferences?.Count > 0;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

.NET 6+ projects always need to restore, so I removed this in main going forward.

MSBuild .binlog files no longer contain environment variables by default.
@jonathanpeppers
Copy link
Member Author

My new test fails with:

MSB4276: The default SDK resolver failed to resolve SDK "Microsoft.NET.Sdk" because directory "C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk" did not exist.

For some reason it tries to import: C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props

But locally, it's importing successfully: D:\src\xamarin-android\bin\Debug\dotnet\sdk\8.0.100-preview.7.23330.16\Sdks\Microsoft.NET.Sdk\Sdk\Sdk.props

@jonathanpeppers
Copy link
Member Author

This isn't needed, as it was/will be addressed by more recent PRs:

@github-actions github-actions bot locked and limited conversation to collaborators Apr 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants