Skip to content

.NET 7 release notes

Rolf Bjarne Kvinge edited this page Nov 10, 2022 · 10 revisions

We're excited to announce our .NET 7 SDK release!

Note: these are the base SDKs that add support for the platforms in question, if you are looking for .NET MAUI (which is built on top of our SDKs), go here instead: https://docs.microsoft.com/en-us/dotnet/maui/.

Getting Started | What's New | Known Issues | Feedback | FAQ

Versions

This release consists of the following versions:

Note that these versions do not support Xcode 14.1, an update with Xcode 14.1 will be released shortly.

Requirements

It's highly recommended to use Xcode 14.0+ (which requires macOS 12.4 (Monterey)). Earlier versions of Xcode may work, but some features won't be available.

With the release the minimum supported OS versions can be targeted for apps:

  • iOS: 10.0
  • macOS: 10.14
  • tvOS: 10.0
  • Mac Catalyst: 13.1

Note: while we support macOS 10.14, we're only testing on OS versions that Apple supports. At the time of this writing this means we're only testing on macOS 11.0+.

Getting started

In contrast to how Xamarin.iOS and Xamarin.Mac were shipped (as installable *.pkg files), our .NET SDKs are shipped as workloads in the .NET world. This means that the first step is to getting started is to install .NET 7.0.100 (or later).

Then install the workload corresponding with the desired platform:

$ dotnet workload install ios # other workloads: macos, tvos, and maccatalyst

Create new app from a template with:

$ dotnet new ios # 'dotnet new --list --tag Mobile' will show all available templates

Finally build and run the new app in the simulator

$ dotnet run

What's New in this Release

This release contains SDKs for the following four platforms: iOS, tvOS, Mac Catalyst and macOS, and has support and bindings for the OS versions that were shipped with Xcode 14.0:

  • iOS 16.0
  • macOS 12.4
  • tvOS 16.0
  • Mac Catalyst 15.4

What's Changed

New Contributors

Full changelog

Breaking Changes

Entitlements.plist is automatically picked up and used for entitlements.

If the root directory of the project file contains an Entitlements.plist file, we'll automatically pick it up and use it for entitlements when signing the app (previously the CodesignEntitlements property would have to be set in the project file).

In the case this is not desired, it's possible to get the old behavior back by setting the EnableDefaultCodesignEntitlements property to false in the project file:

<PropertyGroup>
    <EnableDefaultCodesignEntitlements>false</EnableDefaultCodesignEntitlements>
</EnableDefaultCodesignEntitlements>

Ref: https://github.com/xamarin/xamarin-macios/pull/15729

Release builds for macOS and Mac Catalyst are universal by default.

We've made release builds (builds where Configuration=Release) default to be universal, so that release builds won't have to be translated by Rosetta on ARM64 macOS devices.

If this is not desired, it can be overridden in the project file by doing something like this:

<PropertyGroup Condition="'$(Configuration)' == 'Release'">
    <RuntimeIdentifier>maccatalyst-x64</RuntimeIdentifier>
</PropertyGroup>

Ref: https://github.com/xamarin/xamarin-macios/issues/15620

Iterating over a generic NSArray may require a cast

We've made the NSArray type implement the IEnumerable<NSObject> interface, so now this works:

var array = new NSArray ();
foreach (var element in array) {
    // ...
}

However, this has a somewhat unfortunate side-effect, because enumerating over an instance of the generic NSArray<TKey> type doesn't compile anymore:

var array = new NSArray<NSString> ();
foreach (var element in array) {
    // Fails to compile with:
    // error CS1640: foreach statement cannot operate on variables of type 'NSArray' because it implements multiple instantiations of 'IEnumerable'; try casting to a specific interface instantiation
}

This happens because the NSArray<NSString> instance implements both IEnumerable<NSString> and IEnumerable<NSObject> (since NSArray<NSString> is a subclass of NSArray).

The fix is to cast to IEnumerable<NSString> like this:

var array = new NSArray<NSString> ();
foreach (var element in (IEnumerable<NSString>) array) {
    // This works
}

Unfortunately the compiler error when using LINQ is a bit more confusing:

using System.Linq;
var array = new NSArray<NSString> ();
var list = array.ToList ();
// Fails with:
// Error CS1061: 'NSArray<NSString>' does not contain a definition for 'ToList' and no accessible extension method 'ToList' accepting a first argument of type 'NSArray<NSString>' could be found (are you missing a using directive or an assembly reference?)

On the other hand the solution is somewhat easier on the eyes, just specific the generic type in the call to ToList:

using System.Linq;
var array = new NSArray<NSString> ();
var list = array.ToList<NSString> ();

Note: this does not affect any existing binaries (such as NuGets), it's purely an issue when building from source code.

Ref: https://github.com/xamarin/xamarin-macios/pull/16252

Changed availability attributes

We've taken advantage of the new ObsoletedOSPlatform attribute in .NET 7 in order to properly annotate API that has been obsoleted (previously we had to mark these APIs with an UnsupportedOSPlatform attribute, which didn't describe the situation accurately).

A side-effect of this is that the warning number and text has changed.

For example code like this:

Console.WriteLine (NSColor.WindowFrame);

would previously report CA1416:

Error: AppDelegate.cs(20,27): warning CA1416: This call site is reachable on: 'macOS/OSX' 10.14 and later. 'NSColor.WindowFrame.get' is unsupported on: 'macOS/OSX' 11.0.0 and later.

and now it reports CA1422:

Error: AppDelegate.cs(20,27): error CA1422: This call site is reachable on: 'macOS/OSX' 10.14 and later. 'NSColor.WindowFrame.get' is obsoleted on: 'macOS/OSX' 11.0 and later (Use 'NSVisualEffectMaterial.Title' instead.).
Error: AppDelegate.cs(20,27): error CA1422: This call site is reachable on: 'macOS/OSX' 10.14 and later. 'NSColor.WindowFrame' is obsoleted on: 'macOS/OSX' 11.0 and later (Use 'NSVisualEffectMaterial.Title' instead.).

References:

Known Issues

Hot Reload on device doesn't work

We're aware of an issue where hot reload doesn't work when executing an app on an iOS or tvOS device. This will be fixed in a future service release.

Can't run mobile app from the command line on Windows

It's currently not possible to run a mobile app (iOS, tvOS) on Windows using the command line. Please use an IDE to launch apps from Windows.

Ref: https://github.com/xamarin/xamarin-macios/issues/16609

FAQ

How to run on Device/Simulator from the command line

The general process is documented here:

https://docs.microsoft.com/en-us/dotnet/maui/ios/cli

but does not include running on an attached device.

To do that, include -p:RuntimeIdentifier=ios-arm64, along with the other parameters.

dotnet build -t:Run -f:net7.0-ios -p:RuntimeIdentifier=ios-arm64 -p:_DeviceName=MY_SPECIFIC_UUID

with MY_SPECIFIC_UUID found as described here but for your device.

Note that this does not work from Windows, only from a Mac.

Feedback

File issues here: https://github.com/xamarin/xamarin-macios/issues/new.

Clone this wiki locally