Skip to content

Conversation

@jonathanpeppers
Copy link
Member

Context: dotnet/maui#20752

We think this might catch problems specific to .NET framework going forward.

Context: dotnet/maui#20752

We think this might catch problems specific to .NET framework going forward.
jonpryor pushed a commit that referenced this pull request Feb 21, 2024
Fixes: dotnet/maui#20752

Context: d1ba2cc
Context: dotnet/android-tools@34e98e2
Context: #8746

`dotnet build` (.NET Core) ignores assembly versions.
`msbuild.exe` (.NET Framework) does not.

Enter d1ba2cc, which updates the `libZipSharp.dll` assembly version
from 3.0.0.0 to 3.1.1.0.  However, this change only impacted
`Xamarin.Android.Build.Tasks.dll`:

	% monodis --assemblyref bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/34.99.0/tools/Xamarin.Android.Build.Tasks.dll
	…
	11: Version=3.1.1.0
		Name=libZipSharp
		Flags=0x00000000

It did *not* impact `Microsoft.Android.Build.BaseTasks.dll`, as it
is built by `external/xamarin-android-tools` and was using a
`@(PackageReference)` for libZipSharp 3.0.0:

	% monodis --assemblyref bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/34.99.0/tools/Microsoft.Android.Build.BaseTasks.dll
	…
	5: Version=3.0.0.0
	        Name=libZipSharp
	        Flags=0x00000000

The resulting NuGet package only contains *one* `libZipSharp.dll`,
the 3.1.1.0 version (what `Xamarin.Android.Build.Tasks.dll` refs).

On PR builds and CI, everything was fine, because all the tests we
have use `dotnet build`, and .NET Core ignores assembly versions.

However, if you use *`msbuild.exe`* to invoke the tasks within
`Microsoft.Android.Build.BaseTasks.dll`, things fail:

	XARLP7028 System.IO.FileNotFoundException: Could not load file or assembly 'libZipSharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' or one of its dependencies.
	The system cannot find the file specified.File name: 'libZipSharp, Version=3.0.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

Fix this by adding an `external/xamarin-android-tools.override.props`
file (dotnet/android-tools@34e98e2b) which imports
`Directory.Build.props`, which causes `$(LibZipSharpVersion)` to be
set so that the xamarin-android-tools build uses values provided by
xamarin-android.

TODO: #8746 adds a unit test for the
"build with `msbuild.exe`" scenario.
jonathanpeppers added a commit that referenced this pull request Feb 21, 2024
Fixes: dotnet/maui#20752

Context: d1ba2cc
Context: dotnet/android-tools@34e98e2
Context: #8746

`dotnet build` (.NET Core) ignores assembly versions.
`msbuild.exe` (.NET Framework) does not.

Enter d1ba2cc, which updates the `libZipSharp.dll` assembly version
from 3.0.0.0 to 3.1.1.0.  However, this change only impacted
`Xamarin.Android.Build.Tasks.dll`:

	% monodis --assemblyref bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/34.99.0/tools/Xamarin.Android.Build.Tasks.dll
	…
	11: Version=3.1.1.0
		Name=libZipSharp
		Flags=0x00000000

It did *not* impact `Microsoft.Android.Build.BaseTasks.dll`, as it
is built by `external/xamarin-android-tools` and was using a
`@(PackageReference)` for libZipSharp 3.0.0:

	% monodis --assemblyref bin/Release/lib/packs/Microsoft.Android.Sdk.Darwin/34.99.0/tools/Microsoft.Android.Build.BaseTasks.dll
	…
	5: Version=3.0.0.0
	        Name=libZipSharp
	        Flags=0x00000000

The resulting NuGet package only contains *one* `libZipSharp.dll`,
the 3.1.1.0 version (what `Xamarin.Android.Build.Tasks.dll` refs).

On PR builds and CI, everything was fine, because all the tests we
have use `dotnet build`, and .NET Core ignores assembly versions.

However, if you use *`msbuild.exe`* to invoke the tasks within
`Microsoft.Android.Build.BaseTasks.dll`, things fail:

	XARLP7028 System.IO.FileNotFoundException: Could not load file or assembly 'libZipSharp, Version=3.0.0.0, Culture=neutral, PublicKeyToken=276db85bc4e20efc' or one of its dependencies.
	The system cannot find the file specified.File name: 'libZipSharp, Version=3.0.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

Fix this by adding an `external/xamarin-android-tools.override.props`
file (dotnet/android-tools@34e98e2b) which imports
`Directory.Build.props`, which causes `$(LibZipSharpVersion)` to be
set so that the xamarin-android-tools build uses values provided by
xamarin-android.

TODO: #8746 adds a unit test for the
"build with `msbuild.exe`" scenario.
@jonathanpeppers
Copy link
Member Author

New test failed with:

C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj : error : Could not resolve SDK "Microsoft.NET.Sdk". Exactly one of the probing messages below indicates why we could not resolve the SDK. Investigate and resolve that message to correctly specify the SDK.
C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj : error :   Unable to locate the .NET SDK. Check that it is installed, your PATH is configured for the correct architecture, and that the version specified in global.json (if any) matches the installed version.
C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj : error :   The NuGetSdkResolver did not resolve this SDK because there was no version specified in the project or global.json.
C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj : error :   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.


"C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj" (Restore target) (1) ->
  C:\a\_work\1\a\TestRelease\02-21_19.54.38\temp\BuildWithMSBuildExeTrue\UnnamedProject.csproj : error MSB4236: The SDK 'Microsoft.NET.Sdk' specified could not be found.

    0 Warning(s)
    2 Error(s)

Investigating...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant