Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2b0154e
Add error detection for .NET runtime tasks in older MSBuild versions
Copilot Oct 17, 2025
1cac0ec
Add NETFRAMEWORK-only check for .NET runtime tasks and unit tests
Copilot Oct 17, 2025
6466abb
Improve comment explaining why NETFRAMEWORK check is needed
Copilot Oct 17, 2025
0fdab34
Address code review feedback
Copilot Oct 17, 2025
fe07879
Add end-to-end tests for .NET runtime task error handling
Copilot Oct 17, 2025
edb44a5
Remove NodeProviderOutOfProcTaskHost_Tests that use HandshakeOptions
Copilot Oct 17, 2025
62db1fb
Make test files nullable-aware
Copilot Oct 17, 2025
dc65b51
Apply suggestions from code review
baronfel Oct 17, 2025
fcf4963
Address code review feedback
Copilot Oct 17, 2025
4685ebc
Simplify CLI test to use ProcessIdTask from repo build
Copilot Oct 17, 2025
af1610e
Use AssemblyFile instead of AssemblyName in CLI test
Copilot Oct 17, 2025
e9715d0
Fix CLI test compilation error - construct assembly path dynamically
Copilot Oct 20, 2025
67d9649
Merge remote-tracking branch 'origin/vs17.14' into copilot/improve-er…
Copilot Nov 6, 2025
cd458ac
Fix nullable reference warning in test - extract error message to loc…
Copilot Nov 6, 2025
0d76afa
Fix all nullable reference warnings in test files
Copilot Nov 6, 2025
dd7467d
Fix CLI test to locate Microsoft.Build.Engine.UnitTests.dll correctly
Copilot Nov 6, 2025
7549456
Merge branch 'vs17.14' into copilot/improve-error-message-for-net-tasks
YuliiaKovalova Nov 19, 2025
1bfa333
cleanup
YuliiaKovalova Nov 19, 2025
400cdc2
Update VersionPrefix to 17.14.33
YuliiaKovalova Nov 19, 2025
79f8cc6
Merge branch 'copilot/improve-error-message-for-net-tasks' of https:/…
YuliiaKovalova Nov 19, 2025
ec55124
Address code review feedback
Copilot Nov 19, 2025
a99a860
localized binaries
YuliiaKovalova Nov 19, 2025
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
2 changes: 1 addition & 1 deletion eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the MIT license. See License.txt in the project root for full license information. -->
<Project>
<PropertyGroup>
<VersionPrefix>17.14.32</VersionPrefix>
<VersionPrefix>17.14.33</VersionPrefix>
<DotNetFinalVersionKind>release</DotNetFinalVersionKind>
<PackageValidationBaselineVersion>17.13.9</PackageValidationBaselineVersion>
<AssemblyVersion>15.1.0.0</AssemblyVersion>
Expand Down
62 changes: 62 additions & 0 deletions src/Build.UnitTests/BackEnd/DotNetTaskHost_Tests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.IO;
using Microsoft.Build.Execution;
using Microsoft.Build.UnitTests;
using Shouldly;
using Xunit;
using Xunit.Abstractions;

namespace Microsoft.Build.Engine.UnitTests.BackEnd
{
/// <summary>
/// End-to-end MSBuild CLI tests for .NET Runtime task error handling.
/// These tests verify that MSBuild.exe CLI gives a clear error when attempting to use Runtime="NET" tasks.
/// </summary>
public class DotNetTaskHost_Tests
{
private readonly ITestOutputHelper _output;

public DotNetTaskHost_Tests(ITestOutputHelper output)
{
_output = output;
}

/// <summary>
/// Test that MSBuild.exe gives clear error (MSB4233) when building a project
/// that uses a task with Runtime="NET".
/// </summary>
[WindowsFullFrameworkOnlyFact]
public void CustomTask_WithNetRuntime_ShowsClearError()
{
#if NETFRAMEWORK
using (var env = TestEnvironment.Create(_output))
{
string taskAssemblyPath = Path.Combine(
Path.GetDirectoryName(typeof(DotNetTaskHost_Tests).Assembly.Location) ?? AppContext.BaseDirectory,
"Microsoft.Build.Engine.UnitTests.dll");

string projectContent = $@"
<Project>
<UsingTask TaskName=""ProcessIdTask"" AssemblyFile=""{taskAssemblyPath}"" Runtime=""NET"" />
<Target Name='TestTask'>
<ProcessIdTask>
<Output PropertyName=""PID"" TaskParameter=""Pid"" />
</ProcessIdTask>
</Target>
</Project>";
var logger = new MockLogger(_output);
TransientTestFile project = env.CreateFile("test.csproj", projectContent);
ProjectInstance projectInstance = new(project.Path);
projectInstance.Build(new[] { logger })
.ShouldBeFalse();

logger.ErrorCount.ShouldBeGreaterThan(0);
logger.Errors[0].Code.ShouldBe("MSB4233");
}
#endif
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,20 @@ internal static string GetMSBuildLocationFromHostContext(HandshakeOptions hostCo
/// </summary>
internal bool AcquireAndSetUpHost(HandshakeOptions hostContext, INodePacketFactory factory, INodePacketHandler handler, TaskHostConfiguration configuration)
{
#if NETFRAMEWORK
// MSB4233: Check if .NET runtime is requested, which is not supported in .NET Framework builds of MSBuild (17.14 and earlier).
// All .NET Core/5+ MSBuilds and all 18.0+ builds do support .NET runtime tasks, so this check is not needed there.
// This provides a clear error message instead of the confusing "MSBuild.dll not found" error that would otherwise occur.
if ((hostContext & HandshakeOptions.NET) == HandshakeOptions.NET)
{
ProjectFileErrorUtilities.ThrowInvalidProjectFile(
new BuildEventFileInfo(configuration.ProjectFileOfTask, configuration.LineNumberOfTask, configuration.ColumnNumberOfTask),
"TaskRuntimeNET",
configuration.TaskName,
configuration.TaskLocation);
}
#endif

bool nodeCreationSucceeded;
if (!_nodeContexts.ContainsKey(hostContext))
{
Expand Down
4 changes: 4 additions & 0 deletions src/Build/Resources/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1238,6 +1238,10 @@
<value>MSB4217: Task host node exited prematurely. Diagnostic information may be found in files in the temporary files directory named MSBuild_*.failure.txt. {0}</value>
<comment>{StrBegin="MSB4217: "}</comment>
</data>
<data name="TaskRuntimeNET" xml:space="preserve">
<value>MSB4233: The task "{0}" from assembly "{1}" was specified to load with the .NET runtime, but this version of MSBuild does not support loading tasks with that runtime. To run .NET tasks, use "dotnet build" or Visual Studio 2026 or higher.</value>
<comment>{StrBegin="MSB4233: "}{Locked=".NET"}{Locked="dotnet build"}{Locked="Visual Studio 2026"}LOCALIZATION: .NET, dotnet build, and Visual Studio 2026 should not be localized.</comment>
</data>
<data name="TaskParametersError" xml:space="preserve">
<value>MSB4063: The "{0}" task could not be initialized with its input parameters. {1}</value>
<comment>{StrBegin="MSB4063: "}</comment>
Expand Down
5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.cs.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.de.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.es.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.fr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.it.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ja.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ko.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.pl.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.pt-BR.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.ru.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.tr.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/Build/Resources/xlf/Strings.zh-Hans.xlf

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading