From 639c0e05b35f457e60ce8d0e673732ee77e7f8aa Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 17 Jun 2026 19:08:30 +0200 Subject: [PATCH] Fix using .NET Core assemblies for MSBuild tasks within VS The standard MSBuild task overrides (MakeDir, Copy, Delete, etc.) in Xamarin.Shared.targets exist to support remoting from VS/Windows to a Mac. Previously, they shared the same Runtime and AssemblyFile as our custom tasks (via _TaskRuntime/_TaskAssemblyName), which meant when _TaskRuntime='NET', these standard task overrides would also try to use the .NET task host. This caused MSB4216 errors in Visual Studio because VS couldn't reliably create the .NET task host process (especially on Windows ARM64). The fix introduces separate properties (_RemotingTaskRuntime and _RemotingTaskAssemblyName) for these standard task overrides, which always use the netstandard2.0 assembly with CurrentRuntime. This lets them run in-process without requiring the task host, while our custom tasks (Xamarin.MacDev.Tasks.*) continue to use the .NET Core assemblies via the task host as intended. With this fix, the _UseDesktopTaskAssemblies workaround that forced ALL tasks to use netstandard2.0 when building inside Visual Studio is no longer needed and has been removed. The property is still honored as an escape hatch if explicitly set. Fixes https://github.com/dotnet/macios/issues/25418 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../targets/Microsoft.iOS.Sdk.props | 1 - dotnet/targets/Xamarin.Shared.Sdk.props | 3 --- dotnet/targets/Xamarin.Shared.Sdk.targets | 11 ++++++++++ msbuild/Xamarin.Shared/Xamarin.Shared.targets | 22 +++++++++++-------- 4 files changed, 24 insertions(+), 13 deletions(-) diff --git a/dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props b/dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props index 4f21cc40f0a9..563467607ff5 100644 --- a/dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props +++ b/dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props @@ -4,7 +4,6 @@ <_PlatformName>iOS <_PlatformRidNoArch>ios - <_UseDesktopTaskAssemblies Condition="'$(_UseDesktopTaskAssemblies)' == '' And '$(BuildingInsideVisualStudio)' == 'true'">true $(MSBuildThisFileDirectory)..\tools\msbuild\net$(BundledNETCoreAppTargetFrameworkVersion)\ $(MSBuildThisFileDirectory)..\tools\msbuild\netstandard2.0\ diff --git a/dotnet/targets/Xamarin.Shared.Sdk.props b/dotnet/targets/Xamarin.Shared.Sdk.props index 46c763ae7168..ce84e27e899b 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.props +++ b/dotnet/targets/Xamarin.Shared.Sdk.props @@ -19,9 +19,6 @@ - - <_UseDesktopTaskAssemblies Condition="'$(_UseDesktopTaskAssemblies)' == '' And '$(BuildingInsideVisualStudio)' == 'true'">true - true diff --git a/dotnet/targets/Xamarin.Shared.Sdk.targets b/dotnet/targets/Xamarin.Shared.Sdk.targets index edf3226b5cae..518040e05e5a 100644 --- a/dotnet/targets/Xamarin.Shared.Sdk.targets +++ b/dotnet/targets/Xamarin.Shared.Sdk.targets @@ -15,6 +15,17 @@ <_TaskAssemblyName Condition="'$(_UseDesktopTaskAssemblies)' == 'true'">$(_TaskAssemblyRootDirectory)netstandard2.0\$(_TaskAssemblyFileName) <_TaskRuntime Condition="'$(_UseDesktopTaskAssemblies)' != 'true'">NET <_TaskRuntime Condition="'$(_UseDesktopTaskAssemblies)' == 'true'">CurrentRuntime + + <_DesktopTaskAssemblyName>$(_TaskAssemblyRootDirectory)netstandard2.0\$(_TaskAssemblyFileName) diff --git a/msbuild/Xamarin.Shared/Xamarin.Shared.targets b/msbuild/Xamarin.Shared/Xamarin.Shared.targets index bb5616d012fa..8c64ec01fbf8 100644 --- a/msbuild/Xamarin.Shared/Xamarin.Shared.targets +++ b/msbuild/Xamarin.Shared/Xamarin.Shared.targets @@ -18,15 +18,19 @@ Copyright (C) 2018 Microsoft. All rights reserved. - - - - - - - - - + + + + + + + + +