Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions docs/building-apps/build-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,35 @@ Specifies the minimum tvOS version the app can run on.

Applicable to tvOS; setting this value will set [SupportedOSPlatformVersion](#supportedosplatformversion) for tvOS projects (only).

## UseFloatingTargetPlatformVersion

A boolean property that controls whether library projects should use a floating target platform version or the oldest available platform version.

By default (starting in .NET 10), library projects without an explicit `TargetPlatformVersion` will use the oldest available reference assemblies for the current .NET version. This ensures maximum compatibility and allows library code to compile against the minimum API surface available for the target framework.

However, this default behavior means that library projects are built differently than executable projects (which use the latest platform version). Code that works in an executable project may not compile when moved to a library project if it uses APIs only available in newer platform versions.

Setting this property to `true` disables the automatic selection of the oldest platform version, allowing the library project to use the default (latest) platform version like executable projects do.

Example:

```xml
<PropertyGroup>
<!-- Use the latest platform version instead of the oldest -->
<UseFloatingTargetPlatformVersion>true</UseFloatingTargetPlatformVersion>
</PropertyGroup>
```

Default: `false` (use oldest platform version for library projects in .NET 10+).

This property only applies to library projects (`OutputType=Library`) that are
not app extensions and have not specified an explicit target platform version
(the target platform version is the optional version number at the end of the
`TargetFramework` property, for example for the TargetFramework
`net10.0-ios26.0` the target platform version is explicitly `26.0`).

This property was introduced in .NET 10.

## UseHardenedRuntime

A boolean property that specifies if a hardened runtime is enabled.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@
return max;
}).
ToHashSet ();
var lowestTpvPerMajorDotNet = groupedByMajorDotNetVersion.
Select (gr => {
var min = gr.OrderBy (el => {
var rv = tfmToTpvAndTfv (el);
return float.Parse (rv.Tpv, System.Globalization.CultureInfo.InvariantCulture);
}).First ();
return min;
}).
ToHashSet ();

using (var writer = new StreamWriter (outputPath)) {
writer.WriteLine ($"<Project>");
Expand All @@ -71,7 +80,11 @@
var tpv = parsed.Tpv;
supportedTFVs.Add (tfv);
var workloadVersion = tfm;
writer.WriteLine ($" <ImportGroup Condition=\" '$(TargetPlatformIdentifier)' == '{platform}' And '$(UsingAppleNETSdk)' != 'true' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '{tfv}')) And '$(TargetPlatformVersion)' == '{tpv}'\">");
if (int.Parse (tfv.Split ('.') [0]) >= 10 && lowestTpvPerMajorDotNet.TryGetValue (tfm, out var lowest) && lowest.Split ('_') [1] == tpv) {
writer.WriteLine ($" <ImportGroup Condition=\" '$(TargetPlatformIdentifier)' == '{platform}' And '$(UsingAppleNETSdk)' != 'true' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '{tfv}')) And ('$(TargetPlatformVersion)' == '{tpv}' Or ('$(TargetPlatformVersion)' == '' And '$(OutputType)' == 'Library' And '$(IsAppExtension)' != 'true' And '$(UseFloatingTargetPlatformVersion)' != 'true' And '$(BundleOriginalResources)' != 'false'))\">");
} else {
writer.WriteLine ($" <ImportGroup Condition=\" '$(TargetPlatformIdentifier)' == '{platform}' And '$(UsingAppleNETSdk)' != 'true' And $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '{tfv}')) And '$(TargetPlatformVersion)' == '{tpv}'\">");
}
writer.WriteLine ($" <Import Project=\"Sdk.props\" Sdk=\"Microsoft.{platform}.Sdk.{workloadVersion}\" />");
if (hasWindows)
writer.WriteLine ($" <Import Project=\"Sdk.props\" Sdk=\"Microsoft.{platform}.Windows.Sdk.Aliased.{tfm}\" Condition=\" $([MSBuild]::IsOSPlatform('windows'))\" />");
Expand Down
2 changes: 2 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ test.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Version.De
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(platform)_NUGET_RUNTIME_MANAGED_NAME=$($(platform)_NUGET_RUNTIME_MANAGED_NAME)\\n)" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(rid)_NUGET_RUNTIME_NAME=$($(rid)_NUGET_RUNTIME_NAME)\\n))" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),SUPPORTED_API_VERSIONS_$(platform)='$(SUPPORTED_API_VERSIONS_$(platform))'\\n)" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(platform)_TARGET_PLATFORM_VERSION_LIBRARY=$($(platform)_TARGET_PLATFORM_VERSION_LIBRARY)\\n)" | sed 's/^ //' >> $@
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)\n" >> $@
@printf "ENABLE_ADR=$(ENABLE_ADR)\n" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)\n" >> $@
Expand Down Expand Up @@ -97,6 +98,7 @@ test-system.config: Makefile $(TOP)/Make.config $(TOP)/mk/mono.mk $(TOP)/eng/Ver
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(platform)_NUGET_RUNTIME_MANAGED_NAME=$($(platform)_NUGET_RUNTIME_MANAGED_NAME)\\n)" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(foreach rid,$(DOTNET_$(platform)_RUNTIME_IDENTIFIERS),$(rid)_NUGET_RUNTIME_NAME=$($(rid)_NUGET_RUNTIME_NAME)\\n))" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),SUPPORTED_API_VERSIONS_$(platform)='$(SUPPORTED_API_VERSIONS_$(platform))'\\n)" | sed 's/^ //' >> $@
@printf "$(foreach platform,$(DOTNET_PLATFORMS_UPPERCASE),$(platform)_TARGET_PLATFORM_VERSION_LIBRARY=$($(platform)_TARGET_PLATFORM_VERSION_LIBRARY)\\n)" | sed 's/^ //' >> $@
@printf "ENABLE_XAMARIN=$(ENABLE_XAMARIN)\n" >> $@
@printf "ENABLE_ADR=$(ENABLE_ADR)\n" >> $@
@printf "XCODE_IS_STABLE=$(XCODE_IS_STABLE)\n" >> $@
Expand Down
1 change: 1 addition & 0 deletions tests/common/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ static void ParseConfigFiles ()
ParseConfigFiles (FindConfigFiles ("configure.inc"));
ParseConfigFiles (FindConfigFiles ("Make.config.local"));
ParseConfigFiles (FindConfigFiles ("Make.config"));
ParseConfigFiles (FindConfigFiles ("Make.versions"));
}

static void ParseConfigFiles (IEnumerable<string> files)
Expand Down
8 changes: 0 additions & 8 deletions tests/dotnet/MyClassLibrary/MacCatalyst/MyClass.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-maccatalyst</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

5 changes: 4 additions & 1 deletion tests/dotnet/MyClassLibrary/MyClass.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using System;

using Foundation;

namespace MyClassLibrary {
public class MyClass {
public class MyClass : NSObject {
public MyClass ()
{
}
Expand Down
8 changes: 0 additions & 8 deletions tests/dotnet/MyClassLibrary/iOS/MyClass.cs

This file was deleted.

1 change: 1 addition & 0 deletions tests/dotnet/MyClassLibrary/iOS/MyClassLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-ios</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

8 changes: 0 additions & 8 deletions tests/dotnet/MyClassLibrary/macOS/MyClass.cs

This file was deleted.

1 change: 1 addition & 0 deletions tests/dotnet/MyClassLibrary/macOS/MyClassLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-macos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

6 changes: 6 additions & 0 deletions tests/dotnet/MyClassLibrary/shared.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project>
<ItemGroup>
<Compile Include="../*.cs" />
</ItemGroup>
</Project>
8 changes: 0 additions & 8 deletions tests/dotnet/MyClassLibrary/tvOS/MyClass.cs

This file was deleted.

1 change: 1 addition & 0 deletions tests/dotnet/MyClassLibrary/tvOS/MyClassLibrary.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
<PropertyGroup>
<TargetFramework>net$(BundledNETCoreAppTargetFrameworkVersion)-tvos</TargetFramework>
</PropertyGroup>
<Import Project="..\shared.csproj" />
</Project>

29 changes: 22 additions & 7 deletions tests/dotnet/UnitTests/ProjectTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,33 @@ public void BuildMyCatalystApp (string runtimeIdentifier)
Assert.AreEqual ("3.14", infoPlist.GetString ("CFBundleShortVersionString").Value, "CFBundleShortVersionString");
}

[TestCase ("iOS")]
[TestCase ("tvOS")]
[TestCase ("macOS")]
[TestCase ("MacCatalyst")]
[TestCase (ApplePlatform.iOS)]
[TestCase (ApplePlatform.TVOS)]
[TestCase (ApplePlatform.MacOSX)]
[TestCase (ApplePlatform.MacCatalyst)]
[Category ("WindowsInclusive")]
public void BuildMyClassLibrary (string platform)
public void BuildMyClassLibrary (ApplePlatform platform)
{
Configuration.IgnoreIfIgnoredPlatform (platform);
var project_path = GetProjectPath ("MyClassLibrary", platform);
var configuration = "Debug";
var project = "MyClassLibrary";
var project_path = GetProjectPath (project, platform: platform);
Clean (project_path);
var result = DotNet.AssertBuild (project_path, verbosity);
var properties = GetDefaultProperties ();
var result = DotNet.AssertBuild (project_path, properties);
Assert.That (result.StandardOutput.ToString (), Does.Not.Contain ("Task \"ILLink\""), "Linker executed unexpectedly.");

var expectedReferenceVersionString = Configuration.GetVariable ($"{platform.AsString ().ToUpperInvariant ()}_TARGET_PLATFORM_VERSION_LIBRARY", "");
Assert.That (expectedReferenceVersionString, Is.Not.EqualTo (""), $"Expected to find a default TPV for libraries; this is a problem in the test setup.");

var dll = Path.Combine (Path.GetDirectoryName (project_path)!, "bin", configuration, $"{Configuration.DotNetTfm}-{platform.AsString ()}", project + ".dll");
Assert.That (dll, Does.Exist, "Exists");
using var ad = AssemblyDefinition.ReadAssembly (dll, new ReaderParameters { ReadingMode = ReadingMode.Deferred });
var r = ad.MainModule.AssemblyReferences.Where (v => v.Name == $"Microsoft.{platform.AsString ()}").First ();
var actualReferenceVersionString = $"{r.Version.Major}.{r.Version.Minor}";
Assert.AreEqual (expectedReferenceVersionString, actualReferenceVersionString, $"Referenced version of Microsoft.{platform.AsString ()}.dll");
Assert.That (r.Version.Build, Is.EqualTo (0), "Build");
Assert.That (r.Version.Revision, Is.EqualTo (0), "Revision");
}

[TestCase (ApplePlatform.iOS)]
Expand Down
3 changes: 2 additions & 1 deletion tests/xharness/Harness.cs
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ IEnumerable<string> GetConfigFiles ()
return FindConfigFiles (useSystemXamarinIOSMac ? "test-system.config" : "test.config")
.Concat (FindConfigFiles ("configure.inc"))
.Concat (FindConfigFiles ("Make.config"))
.Concat (FindConfigFiles ("Make.config.local"));
.Concat (FindConfigFiles ("Make.config.local"))
.Concat (FindConfigFiles ("Make.versions"));
}

void ParseConfigFile (string file, Dictionary<string, string> configuration)
Expand Down
Loading