Skip to content
This repository has been archived by the owner on Jan 18, 2023. It is now read-only.

[build] support for .NET 5.0+ #6

Merged
merged 1 commit into from
Aug 21, 2020

Conversation

jonathanpeppers
Copy link
Member

@jonathanpeppers jonathanpeppers commented Aug 20, 2020

Trying to build an F# project under .NET 5 fails with:

error FS3053 : The type provider 'Xamarin.Android.FSharp.ResourceProvider' reported an error : The type provider constructor has thrown an exception: Could not load file or assembly 'System.CodeDom, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

We need this library to target netstandard2.0, so it will work on
.NET framework, Mono, and .NET Core (.NET 5+). I reworked
Xamarin.Android.FSharp.ResourceProvider.fsproj to be
netstandard2.0.

This created a new issue when I tried to use the package in a .NET 5
project:

Foo.Android.fsproj : error NU1202: Package Xamarin.Android.FSharp.ResourceProvider 1.0.0.29 is not compatible with net5.0 (net5.0). Package Xamarin.Android.FSharp.ResourceProvider 1.0.0.29 supports:
Foo.Android.fsproj : error NU1202:   - monoandroid81 (MonoAndroid,Version=v8.1)
Foo.Android.fsproj : error NU1202:   - netstandard2.0 (.NETStandard,Version=v2.0)

.NET 5.0 seems to prefer netstandard2.0 over monoandroid81, and so
it doesn't know what to do here: hence the error.

I literally, could run this command on the package and it works afterward:

zip -d Xamarin.Android.FSharp.ResourceProvider.1.0.0.29.nupkg lib/netstandard2.0/Xamarin.Android.Fsharp.ResourceProvider.dll

The fix is to use the .nuspec instead of the .fsproj:

-nuget pack Xamarin.Android.FSharp.ResourceProvider.fsproj
+nuget pack Xamarin.Android.FSharp.ResourceProvider.nuspec

I also made some changes to the Xamarin.Android project (just general
cleanup):

  • Migrate from packages.config to @(PackageReference)
  • We can rely on /restore now in the build definition.
    restoreNugetPackages is deprecated, so we shouldn't use it.
  • Removed an <Import/> that was unused.

@jonathanpeppers jonathanpeppers marked this pull request as draft August 21, 2020 12:34
@jonathanpeppers
Copy link
Member Author

This will need #7 first.

@jonathanpeppers jonathanpeppers marked this pull request as ready for review August 21, 2020 15:00
@pjcollins
Copy link
Member

Should we bump the package version in the nuspec here?

azure-pipelines.yml Outdated Show resolved Hide resolved
@jonathanpeppers jonathanpeppers marked this pull request as draft August 21, 2020 15:41
Trying to build an F# project under .NET 5 fails with:

    error FS3053 : The type provider 'Xamarin.Android.FSharp.ResourceProvider' reported an error : The type provider constructor has thrown an exception: Could not load file or assembly 'System.CodeDom, Version=0.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

We need this library to target `netstandard2.0`, so it will work on
.NET framework, Mono, and .NET Core (.NET 5+). I reworked
`Xamarin.Android.FSharp.ResourceProvider.fsproj` to be
`netstandard2.0`.

This created a new issue when I tried to *use* the package in a .NET 5
project:

    Foo.Android.fsproj : error NU1202: Package Xamarin.Android.FSharp.ResourceProvider 1.0.0.29 is not compatible with net5.0 (net5.0). Package Xamarin.Android.FSharp.ResourceProvider 1.0.0.29 supports:
    Foo.Android.fsproj : error NU1202:   - monoandroid81 (MonoAndroid,Version=v8.1)
    Foo.Android.fsproj : error NU1202:   - netstandard2.0 (.NETStandard,Version=v2.0)

.NET 5.0 seems to prefer `netstandard2.0` over `monoandroid81`, and so
it doesn't know what to do here: hence the error.

I literally, could run this command on the package and it works afterward:

    zip -d Xamarin.Android.FSharp.ResourceProvider.1.0.0.29.nupkg lib/netstandard2.0/Xamarin.Android.Fsharp.ResourceProvider.dll

The fix is to use the `.nuspec` instead of the `.fsproj`:

    -nuget pack Xamarin.Android.FSharp.ResourceProvider.fsproj
    +nuget pack Xamarin.Android.FSharp.ResourceProvider.nuspec

I also made some changes to the Xamarin.Android project (just general
cleanup):

* Migrate from `packages.config` to `@(PackageReference)`
* We can rely on `/restore` now in the build definition.
  `restoreNugetPackages` is deprecated, so we shouldn't use it.
* Removed an `<Import/>` that was unused.
@jonathanpeppers jonathanpeppers merged commit ab48982 into xamarin:master Aug 21, 2020
@jonathanpeppers jonathanpeppers deleted the net5.0 branch August 21, 2020 15:53
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Aug 21, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Aug 21, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Aug 24, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Sep 1, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.
jonathanpeppers added a commit to jonathanpeppers/xamarin-android that referenced this pull request Sep 1, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.
jonathanpeppers added a commit to dotnet/android that referenced this pull request Sep 2, 2020
Context: xamarin/Xamarin.Android.FSharp.ResourceProvider#6

Xamarin.Android.FSharp.ResourceProvider 1.0.1 is now built for
`netstandard2.0` and published to an internal feed.

We should be able to enable F# tests under a `dotnet` context now.

The `_RemoveLegacyDesigner` MSBuild target was running, when it
shouldn't be for F# projects and adding a `Resource.designer.cs`
`@(Compile)` item. I needed to add a `$(Language)` check.

One workaround is for:

dotnet/sdk#12954

We need to set `$(ProduceReferenceAssembly)` to `false` for .NET 5 F#
projects at the moment.

The second workaround is for:

dotnet/linker#1448

F# generics are causing an NRE in the linker.
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