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

[.NET 5] use $(OutputType) Exe for application vs library #4604

Merged
merged 1 commit into from
Apr 24, 2020

Conversation

jonathanpeppers
Copy link
Member

In .NET 5, Xamarin.iOS is already using <OutputType>Exe<OutputType>
to distinguish an iOS application vs an iOS class library.

Xamarin.Android, however, is checking the existence of
Properties/AndroidManifest.xml.

This brings up some issues:

  • When using a multi-targeted project in .NET, we should be using the
    same convention to distinguish library vs applications on both iOS
    and Android.
  • Xamarin.iOS apps have a static void Main method. OutputType=Exe
    makes sense, as it tells Roslyn to expect a Main method.

To consolidate this, I propose:

  • Use $(OutputType) of Exe to set $(AndroidApplication) to
    true. No longer look for AndroidManifest.xml for this default.
  • Immediately set $(OutputType) to Library, since we never want a
    Main method on Android.

To make this work, I had to move these defaults from
Xamarin.Android.Sdk.props to Xamarin.Android.Sdk.targets. This
allows these properties to be evaluated after the values set in the
user's project.

I added a test that builds a library, checking that the
__AndroidLibraryProjects__.zip EmbeddedResource has the correct
contents.

In .NET 5, Xamarin.iOS is already using `<OutputType>Exe<OutputType>`
to distinguish an iOS application vs an iOS class library.

Xamarin.Android, however, is checking the existence of
`Properties/AndroidManifest.xml`.

This brings up some issues:

* When using a multi-targeted project in .NET, we should be using the
  same convention to distinguish library vs applications on both iOS
  and Android.
* Xamarin.iOS apps have a `static void Main` method. `OutputType=Exe`
  makes sense, as it tells Roslyn to expect a `Main` method.

To consolidate this, I propose:

* Use `$(OutputType)` of `Exe` to set `$(AndroidApplication)` to
  `true`. No longer look for `AndroidManifest.xml` for this default.
* Immediately set `$(OutputType)` to `Library`, since we *never* want a
  `Main` method on Android.

To make this work, I had to move these defaults from
`Xamarin.Android.Sdk.props` to `Xamarin.Android.Sdk.targets`. This
allows these properties to be evaluated *after* the values set in the
user's project.

I added a test that builds a library, checking that the
`__AndroidLibraryProjects__.zip` `EmbeddedResource` has the correct
contents.
@jonpryor jonpryor merged commit 7b9463b into dotnet:master Apr 24, 2020
@jonathanpeppers jonathanpeppers deleted the net5-outputtype-exe branch April 24, 2020 19:50
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Apr 29, 2020
* `$(OutputType)` = `Exe` is what flags an app vs library

dotnet/android#4604

* New `Run` target

dotnet/android#4609
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Apr 29, 2020
* `$(OutputType)` = `Exe` is what flags an app vs library

dotnet/android#4604

* New `Run` target

dotnet/android#4609
jonathanpeppers added a commit to dotnet/maui-samples that referenced this pull request Apr 29, 2020
* `$(OutputType)` = `Exe` is what flags an app vs library

dotnet/android#4604

* New `Run` target

dotnet/android#4609
@github-actions github-actions bot locked and limited conversation to collaborators Jan 24, 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.

5 participants