Skip to content

Conversation

@jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Sep 29, 2017

Context: https://github.com/jonathanpeppers/xabuild

xabuild.exe is a nice wrapper around MSBuild for compiling
Xamarin.Android projects using a locally built version of
Xamarin.Android on your system. It seems to work on Windows, MacOS, and
Linux and doesn’t require elevation or modify your system.

xabuild.exe works by doing the following:

  • Reference MSBuild.exe or MSBuild.dll depending on the platform
  • Overrides the app.config file of MSBuild to set various properties
  • This allows xabuild.exe to build Xamarin.Android projects using
    local Xamarin.Android build output
  • Creates symbolic links to .NETPortable and .NETFramework
    directories inside the Xamarin.Android build output directory
  • Run MSBuild’s Main() method

Changes

  • Added xabuild.csproj to Xamarin.Android.sln
  • tools/scripts/xabuild now runs xabuild.exe if MSBUILD=msbuild
  • Xamarin.Android.Build.Tests run tools/scripts/xabuild on Unix
    and xabuild.exe on Windows

Usage

An example on MacOS:

$ make prepare all MSBUILD=msbuild
$ make all-tests MSBUILD=msbuild
$ make run-nunit-tests MSBUILD=msbuild NUNIT_TESTS=bin/TestDebug/Xamarin.Android.Build.Tests.dll

An example on Windows (msbuild should be 15.3 from VS 2017):

> msbuild build-tools\scripts\PrepareWindows.targets
> msbuild Xamarin.Android.sln
> bin\Debug\bin\xabuild.exe Xamarin.Android-Tests.sln /p:XAIntegratedTests=False
> packages\NUnit.ConsoleRunner.3.7.0\tools\nunit3-console.exe bin\TestDebug\Xamarin.Android.Build.Tests.dll

Note, these tests are not all passing on Windows yet. See here for latest results.

@jonathanpeppers jonathanpeppers added the do-not-merge PR should not be merged. label Sep 29, 2017
@dnfclas
Copy link

dnfclas commented Sep 29, 2017

@jonathanpeppers,
Thanks for having already signed the Contribution License Agreement. Your agreement was validated by .NET Foundation. We will now review your pull request.
Thanks,
.NET Foundation Pull Request Bot

@jonathanpeppers jonathanpeppers force-pushed the xabuild.exe branch 2 times, most recently from c3ff372 to 7314265 Compare October 12, 2017 13:17
CONFIGURATION=$word
break
done

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed a slight issue here. If you run the command:

tools/scripts/xabuild /p:Configuration=Release someProjectOrSolution.csproj

Then $CONFIGURATION was coming out set to Release someProjectOrSolution.csproj.

Let me know if there is a better way to fix this, I'm not exactly a bash expert. 😄

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the actual problem is line 46: it should use "$@", not "$*":

https://unix.stackexchange.com/a/129077

@jonathanpeppers jonathanpeppers changed the title WIP [xabuild.exe] cross-platform form of tools/scripts/xabuild [xabuild.exe] cross-platform form of tools/scripts/xabuild Oct 12, 2017
@jonathanpeppers jonathanpeppers removed the do-not-merge PR should not be merged. label Oct 12, 2017
done
fi

if [[ "$MSBUILD" == "msbuild" ]] ; then
Copy link
Contributor

Choose a reason for hiding this comment

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

This "block" should be moved to ~line 84, after $prefix is set. $prefix contains the $CONFIGURATION to use.

fi

if [[ "$MSBUILD" == "msbuild" ]] ; then
if [ -z "$CONFIGURATION" ]; then
Copy link
Contributor

Choose a reason for hiding this comment

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

...by using $prefix, this check is superfluous.

if [ -z "$CONFIGURATION" ]; then
CONFIGURATION="Debug"
fi
exec mono "$prefix/../../bin/$CONFIGURATION/bin/xabuild.exe" "$@"
Copy link
Contributor

Choose a reason for hiding this comment

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

This would need to then become $prefix/bin/xabuild.exe.

Context: https://github.com/jonathanpeppers/xabuild

xabuild.exe is a nice wrapper around MSBuild for compiling
Xamarin.Android projects using a locally built version of
Xamarin.Android on your system. It seems to work on Windows, MacOS, and
Linux and doesn’t require elevation or modify your system.

xabuild.exe works by doing the following:
- Reference `MSBuild.exe` or `MSBuild.dll` depending on the platform
- Overrides the `app.config` file of MSBuild to set various properties
- This allows `xabuild.exe` to build Xamarin.Android projects using
local Xamarin.Android build output
- Creates symbolic links to `.NETPortable` and `.NETFramework`
directories inside the Xamarin.Android build output directory
- Run MSBuild’s `Main()` method

Changes:
- Added `xabuild.csproj` to Xamarin.Android.sln
- `tools/scripts/xabuild` now runs `xabuild.exe` if `MSBUILD=msbuild`
- Xamarin.Android.Build.Tests run `tools/scripts/xabuild` on Unix
and `xabuild.exe` on Windows
@jonpryor jonpryor merged commit f9d15dd into dotnet:master Oct 13, 2017
@jonathanpeppers jonathanpeppers deleted the xabuild.exe branch October 16, 2017 12:35
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Oct 25, 2017
Context in dotnet#910

When switching to `xabuild.exe`, two mistakes were made:
- `xabuild.exe` shouldn’t set `AndroidSdkDirectory` or
`AndroidNdkDirectory`
- Xamarin.Android.Build.Tests should pass these values to xabuild

This restores some of the code in `Builder.cs` removed in f9d15dd
Redth pushed a commit to Redth/xamarin-android that referenced this pull request Oct 30, 2017
Context: https://github.com/jonathanpeppers/xabuild

What do we want? A *usable*, *parallel*, build tree.

To elaborate: we want to be able to have a "system" Xamarin.Android
install, and a "parallel" xamarin-android install, and be able to
*easily* switch between the two. (For various definitions of "easy";
here, we mean *command-line* use, not IDE use.)

On macOS, this (more or less) Just Works™, and is extremely handy
for testing bug fixes:

	$ xbuild /t:Install Project.csproj
	# Verify that some bug is triggered

	$ xbuild /t:Uninstall Project.csproj
	$ tools/scripts/xabuild /t:Install Project.csproj
	# Verify that some bug is *fixed*

There's One Problem™ with this: MSBuild does not make this easy.
(Related: commit aa1db83.) Apps may rely on files located within
`$(MSBuildExtensionsPath)` or `$(TargetFrameworkRootPath)`, files
such as PCL profile assemblies, or 3rd party frameworks.

Meanwhile, on macOS, `xabuild` is *predicated* upon overriding
`$(TargetFrameworkRootPath)` and `$(MSBuildExtensionsPath)` and
`$(XBUILD_FRAMEWORK_FOLDERS_PATH)`, and creating a bunch of symlinks
to "fake out" `msbuild.exe` so that system-installed files such as
PCL assemblies can be found *through* the parallel environment.

It kinda/sorta works on macOS. It completely falls apart when using
Windows. There is no easy "symlink half the world" solution there.
Overriding `$(MSBuildExtensionsPath)` means that
`Microsoft.Common.targets` can't be found. Overriding
`$(TargetFrameworkRootPath)` means PCL files can't be found.

It's a mess.

Fortunately, more recent versions of MSBuild allow for some of these
properties to contain *multiple* directories instead of a single
directory, which means *there is a way* to support our desired
usable parallel install world order. We "just" need to e.g.
force `$(MSBuildExtensionsPath)` to contain *both* the in-tree
directory *and* the system directory:

```xml
<MSBuildExtensionsPath>In-Tree Directory; System Directory</MSBuildExtensionsPath>
```

Unfortunately, *this isn't easy*. Not all of these properties can be
overridden on the `msbuild.exe` command line. Worse, MSBuild doesn't
allow `;` to be part of a property value, as `;` is a property name
[separator char](https://msdn.microsoft.com/en-us/library/ms164311.aspx)

	msbuild.exe /property:WarningLevel=2;OutDir=bin\Debug

The way to force MSBuild to accept multiple paths in a property value
is by providing a `.exe.config` file with the appropriate values.

~~ Enter `xabuild.exe` ~~

`xabuild.exe` is a nice wrapper around MSBuild for compiling
Xamarin.Android projects using a locally built version of
Xamarin.Android on your system. It seems to work on Windows, macOS, and
Linux and doesn’t require elevation or modifications to your system.

`xabuild.exe` works by doing the following:

 1. Reference `MSBuild.exe` or `MSBuild.dll` depending on the platform
 2. Creates symbolic links to `.NETPortable` and `.NETFramework`
    directories inside the Xamarin.Android build output directory
 3. Overrides MSBuild's `app.config` file to set various properties,
    such as `$(MSBuildExtensionsPath)`.
 4. Run MSBuild’s `Main()` method

~~ Usage ~~

On macOS, `tools/scripts/xabuild` has been updated to use
`xabuild.exe` when `$MSBUILD` is `msbuild:

	$ MSBUILD=msbuild tools/scripts/xabuild /t:SignAndroidPackage samples/HelloWorld/HelloWorld.csproj

When `$MSBUILD` is `xbuild` (the current default), the previous
behavior of overriding `$MSBuildExtensionsPath` and
`$XBUILD_FRAMEWORK_FOLDERS_PATH` is still used.

On Windows, MSBuild 15.3 from Visual Studio 2017 is required.
Simply execute `xabuild.exe`:

	> bin\Debug\bin\xabuild.exe Xamarin.Android-Tests.sln /p:XAIntegratedTests=False

Before `xabuild.exe` existed, `setup-windows.exe` would need to be
executed (as Administrator!) in order for `Xamarin.Android-Tests.sln`
to be built using `msbuild.exe`.
@github-actions github-actions bot locked and limited conversation to collaborators Feb 5, 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.

3 participants