Fix using .NET Core assemblies for MSBuild tasks within VS#25722
Fix using .NET Core assemblies for MSBuild tasks within VS#25722rolfbjarne wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes Visual Studio build failures (MSB4216) when using the .NET (task-hosted) MSBuild task assemblies by separating the runtime/assembly selection for standard MSBuild task overrides (Copy/Delete/MakeDir/etc, used for remoting) from custom Xamarin.MacDev.Tasks.
Changes:
- Introduces
_RemotingTaskRuntime/_RemotingTaskAssemblyName(netstandard2.0 +CurrentRuntime) for the standard task overrides to keep them in-process. - Updates
Xamarin.Shared.targetsto use the new remoting properties for the overridden built-in tasks. - Removes the automatic
_UseDesktopTaskAssemblies“VS workaround” from the .NET SDK props (leaving it as an explicit escape hatch only).
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| msbuild/Xamarin.Shared/Xamarin.Shared.targets | Switches built-in task override UsingTasks to _RemotingTask* properties. |
| dotnet/targets/Xamarin.Shared.Sdk.targets | Defines _RemotingTaskRuntime/_RemotingTaskAssemblyName alongside existing task runtime/assembly properties. |
| dotnet/targets/Xamarin.Shared.Sdk.props | Removes auto-enabling _UseDesktopTaskAssemblies for Visual Studio builds. |
| dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props | Removes auto-enabling _UseDesktopTaskAssemblies for Visual Studio builds. |
| <!-- Tasks that override built-in tasks to support remoting from VS/Windows. | ||
| These always use the netstandard2.0 assembly with CurrentRuntime (via _RemotingTaskRuntime/_RemotingTaskAssemblyName) | ||
| so they run in-process and don't require the .NET task host. Using Runtime="NET" for these overrides | ||
| causes failures in VS because the task host can't be created reliably (especially on ARM64). --> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.Copy" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.Delete" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.Exec" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.MakeDir" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.Move" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.RemoveDir" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.Touch" AssemblyFile="$(_RemotingTaskAssemblyName)" /> | ||
| <UsingTask Runtime="$(_RemotingTaskRuntime)" TaskName="Microsoft.Build.Tasks.WriteLinesToFile" AssemblyFile="$(_RemotingTaskAssemblyName)" /> |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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 #25418 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
961d65d to
e5576b7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ [PR Build #e5576b7] Build passed (Build macOS tests) ✅Pipeline on Agent |
🔥 [CI Build #e5576b7] Build failed (Build packages) 🔥Build failed for the job 'Build packages' (with job status 'Failed') Pipeline on Agent |
✅ [CI Build #e5576b7] Build passed (Detect API changes) ✅Pipeline on Agent |
✅ API diff for current PR / commitNET (empty diffs)✅ API diff vs stableNET (empty diffs)ℹ️ Generator diffGenerator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes) Pipeline on Agent |
This comment has been minimized.
This comment has been minimized.
🔥 [CI Build #e5576b7] Test results 🔥Test results❌ Tests failed on VSTS: test results 1 tests crashed, 1 tests failed, 192 tests passed. Failures❌ assembly-processing tests [attempt 2]🔥 Failed catastrophically on VSTS: test results - assembly-processing (no summary found). Html Report (VSDrops) Download ❌ windows tests1 tests failed, 2 tests passed.Failed tests
Html Report (VSDrops) Download Successes✅ cecil: All 1 tests passed. Html Report (VSDrops) Download macOS tests✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download Linux Build VerificationPipeline on Agent |
Summary
Fixes the root cause that prevented using .NET Core assemblies for MSBuild tasks when building inside Visual Studio, removing the
_UseDesktopTaskAssembliesworkaround added in #25417 and #25662.Root Cause
The standard MSBuild task overrides (
MakeDir,Copy,Delete,Exec,Move,RemoveDir,Touch,WriteLinesToFile) inmsbuild/Xamarin.Shared/Xamarin.Shared.targetsexist to support remoting from VS/Windows to a Mac. They were sharing the sameRuntimeandAssemblyFileproperties (_TaskRuntime/_TaskAssemblyName) as our custom tasks. When_TaskRuntime=NET, these standard task overrides were forced through the .NET task host, which VS couldn't reliably create — causingMSB4216errors like:Fix
Introduce separate properties (
_RemotingTaskRuntimeand_RemotingTaskAssemblyName) for the standard MSBuild task overrides:MakeDir,Copy, etc.): Always usenetstandard2.0+CurrentRuntime→ run in-process, no task host neededXamarin.MacDev.Tasks.*): Continue using .NET Core assemblies +Runtime="NET"→ use the task host as intendedThis separation is correct because the standard task overrides only add remoting logic on top of the built-in MSBuild tasks — they don't need .NET Core APIs and work perfectly fine with the
netstandard2.0assembly running in-process.Changes
dotnet/targets/Xamarin.Shared.Sdk.targets_RemotingTaskAssemblyNameand_RemotingTaskRuntimeproperties (alwaysnetstandard2.0+CurrentRuntime)msbuild/Xamarin.Shared/Xamarin.Shared.targetsUsingTaskdeclarations to use the new remoting propertiesdotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props_UseDesktopTaskAssembliesworkaround for VSdotnet/targets/Xamarin.Shared.Sdk.props_UseDesktopTaskAssembliesworkaround for VSFixes #25418