Skip to content

Fix using .NET Core assemblies for MSBuild tasks within VS#25722

Draft
rolfbjarne wants to merge 1 commit into
mainfrom
rolfbjarne/fix-dotnet-core-msbuild-tasks-in-vs
Draft

Fix using .NET Core assemblies for MSBuild tasks within VS#25722
rolfbjarne wants to merge 1 commit into
mainfrom
rolfbjarne/fix-dotnet-core-msbuild-tasks-in-vs

Conversation

@rolfbjarne

Copy link
Copy Markdown
Member

Summary

Fixes the root cause that prevented using .NET Core assemblies for MSBuild tasks when building inside Visual Studio, removing the _UseDesktopTaskAssemblies workaround added in #25417 and #25662.

Root Cause

The standard MSBuild task overrides (MakeDir, Copy, Delete, Exec, Move, RemoveDir, Touch, WriteLinesToFile) in msbuild/Xamarin.Shared/Xamarin.Shared.targets exist to support remoting from VS/Windows to a Mac. They were sharing the same Runtime and AssemblyFile properties (_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 — causing MSB4216 errors like:

error MSB4216: Could not run the "MakeDir" task because MSBuild could not create
or connect to a task host with runtime "NET" and architecture "*".

Fix

Introduce separate properties (_RemotingTaskRuntime and _RemotingTaskAssemblyName) for the standard MSBuild task overrides:

  • Standard task overrides (MakeDir, Copy, etc.): Always use netstandard2.0 + CurrentRuntime → run in-process, no task host needed
  • Custom tasks (Xamarin.MacDev.Tasks.*): Continue using .NET Core assemblies + Runtime="NET" → use the task host as intended

This 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.0 assembly running in-process.

Changes

File Change
dotnet/targets/Xamarin.Shared.Sdk.targets Add _RemotingTaskAssemblyName and _RemotingTaskRuntime properties (always netstandard2.0 + CurrentRuntime)
msbuild/Xamarin.Shared/Xamarin.Shared.targets Update standard task override UsingTask declarations to use the new remoting properties
dotnet/Microsoft.iOS.Sdk/targets/Microsoft.iOS.Sdk.props Remove _UseDesktopTaskAssemblies workaround for VS
dotnet/targets/Xamarin.Shared.Sdk.props Remove _UseDesktopTaskAssemblies workaround for VS

Note: _UseDesktopTaskAssemblies is still honored as an escape hatch if explicitly set — it just isn't automatically enabled for VS builds anymore.

Fixes #25418

Copilot AI review requested due to automatic review settings June 17, 2026 17:31
@rolfbjarne rolfbjarne requested a review from mauroa as a code owner June 17, 2026 17:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.targets to 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.

Comment on lines +21 to +32
<!-- 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)" />
@vs-mobiletools-engineering-service2

This comment has been minimized.

@rolfbjarne rolfbjarne marked this pull request as draft June 17, 2026 17:49
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

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>
@rolfbjarne rolfbjarne force-pushed the rolfbjarne/fix-dotnet-core-msbuild-tasks-in-vs branch from 961d65d to e5576b7 Compare June 18, 2026 16:56
@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [PR Build #e5576b7] Build passed (Build macOS tests) ✅

Pipeline on Agent
Hash: e5576b7096ed9eb6f83dbdf51e25f385885ea2e0 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [CI Build #e5576b7] Build failed (Build packages) 🔥

Build failed for the job 'Build packages' (with job status 'Failed')

Pipeline on Agent
Hash: e5576b7096ed9eb6f83dbdf51e25f385885ea2e0 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ [CI Build #e5576b7] Build passed (Detect API changes) ✅

Pipeline on Agent
Hash: e5576b7096ed9eb6f83dbdf51e25f385885ea2e0 [PR build]

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

✅ API diff for current PR / commit

NET (empty diffs)

✅ API diff vs stable

NET (empty diffs)

ℹ️ Generator diff

Generator Diff: vsdrops (html) vsdrops (raw diff) gist (raw diff) - Please review changes)

Pipeline on Agent
Hash: e5576b7096ed9eb6f83dbdf51e25f385885ea2e0 [PR build]

@vs-mobiletools-engineering-service2

This comment has been minimized.

@vs-mobiletools-engineering-service2

Copy link
Copy Markdown
Collaborator

🔥 [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 tests

1 tests failed, 2 tests passed.

Failed tests

  • Remote .NET tests/Xamarin.Tests.IncrementalBuildTest.CodeChangeSkipsTargetsOnRemoteWindows(iOS,"iossimulator-arm64",True): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.StripTest(iOS,"ios-arm64","Release"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.AppWithLibraryWithResourcesReferenceOnRemoteWindows(iOS,"ios-arm64",True): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.BundleStructureWithRemoteMac(iOS,"ios-arm64",All,"Debug"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.DotNetProjectTest.BuildProjectsWithExtensionsOnRemoteWindows(iOS,"ios-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.IncrementalBuildTest.CodeChangeSkipsTargetsOnRemoteWindows(iOS,"iossimulator-arm64",False): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.RemoteTest(iOS,"ios-arm64"): Failed: 'dotnet build' failed with exit code 1

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"iossimulator-arm64;iossimulator-x64"): Failed: 'dotnet build' timed out after 00:10:00

  • Remote .NET tests/Xamarin.Tests.WindowsTest.PluralRuntimeIdentifiersWithRemoteMac(iOS,"ios-arm64"): Failed: 'dotnet build' timed out after 00:10:00

  • Remote .NET tests/Xamarin.Tests.WindowsTest.BuildEmbeddedFrameworkInBindingProjectApp(iOS,"iossimulator-arm64"): Failed: 'dotnet build' failed with exit code 1

Html Report (VSDrops) Download

Successes

✅ cecil: All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (iOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (MacCatalyst): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (macOS): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (Multiple platforms): All 1 tests passed. Html Report (VSDrops) Download
✅ dotnettests (tvOS): All 1 tests passed. Html Report (VSDrops) Download
✅ framework: All 2 tests passed. Html Report (VSDrops) Download
✅ fsharp: All 4 tests passed. Html Report (VSDrops) Download
✅ generator: All 5 tests passed. Html Report (VSDrops) Download
✅ interdependent-binding-projects: All 4 tests passed. Html Report (VSDrops) Download
✅ introspection: All 6 tests passed. Html Report (VSDrops) Download
✅ linker (iOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (MacCatalyst): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (macOS): All 11 tests passed. Html Report (VSDrops) Download
✅ linker (tvOS): All 11 tests passed. Html Report (VSDrops) Download
✅ monotouch (iOS): All 20 tests passed. [attempt 2] Html Report (VSDrops) Download
✅ monotouch (MacCatalyst): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (macOS): All 23 tests passed. Html Report (VSDrops) Download
✅ monotouch (tvOS): All 20 tests passed. Html Report (VSDrops) Download
✅ msbuild: All 2 tests passed. Html Report (VSDrops) Download
✅ sharpie: All 1 tests passed. Html Report (VSDrops) Download
✅ xcframework: All 4 tests passed. Html Report (VSDrops) Download
✅ xtro: All 1 tests passed. Html Report (VSDrops) Download

macOS tests

✅ Tests on macOS Monterey (12): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Ventura (13): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sonoma (14): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Sequoia (15): All 5 tests passed. Html Report (VSDrops) Download
✅ Tests on macOS Tahoe (26): All 5 tests passed. Html Report (VSDrops) Download

Linux Build Verification

Linux build succeeded

Pipeline on Agent
Hash: e5576b7096ed9eb6f83dbdf51e25f385885ea2e0 [PR build]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix using .NET Core assemblies for MSBuild tasks within VS

3 participants