-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add clear error message (MSB4233) for .NET runtime tasks on MSBuild 17.14 #12662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: vs17.14
Are you sure you want to change the base?
Changes from all commits
2b0154e
1cac0ec
6466abb
0fdab34
fe07879
edb44a5
62db1fb
dc65b51
fcf4963
4685ebc
af1610e
e9715d0
67d9649
cd458ac
0d76afa
dd7467d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,77 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using Microsoft.Build.Evaluation; | ||
| using Microsoft.Build.Execution; | ||
| using Microsoft.Build.Framework; | ||
| using Microsoft.Build.UnitTests; | ||
| using Shouldly; | ||
| using Xunit; | ||
| using Xunit.Abstractions; | ||
| using Xunit.NetCore.Extensions; | ||
|
|
||
| namespace Microsoft.Build.Engine.UnitTests.BackEnd | ||
| { | ||
| /// <summary> | ||
| /// End-to-end tests for .NET Runtime task error handling. | ||
| /// These tests verify that MSBuild 17.14 gives a clear error when attempting to use Runtime="NET" tasks. | ||
| /// </summary> | ||
| public class DotNetRuntimeTask_EndToEnd_Tests | ||
| { | ||
| private readonly ITestOutputHelper _output; | ||
|
|
||
| public DotNetRuntimeTask_EndToEnd_Tests(ITestOutputHelper output) | ||
| { | ||
| _output = output; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Test that BuildManager API gives clear error (MSB4233) when attempting to build a project | ||
| /// that uses a task with Runtime="NET". | ||
| /// </summary> | ||
| [WindowsFullFrameworkOnlyFact] | ||
| public void BuildManager_WithDotNetRuntimeTask_ShowsClearError() | ||
| { | ||
| // This test uses a real task but specifies Runtime="NET" which is not supported on .NET Framework builds. | ||
| // We expect the build to fail with MSB4233 error that clearly explains the issue. | ||
| #if NETFRAMEWORK | ||
| string projectContent = @" | ||
| <Project> | ||
| <UsingTask TaskName=""ProcessIdTask"" AssemblyName=""Microsoft.Build.Engine.UnitTests"" Runtime=""NET"" /> | ||
| <Target Name='TestTask'> | ||
| <ProcessIdTask> | ||
| <Output PropertyName=""PID"" TaskParameter=""Pid"" /> | ||
| </ProcessIdTask> | ||
| </Target> | ||
| </Project>"; | ||
|
|
||
| using (var env = TestEnvironment.Create(_output)) | ||
| { | ||
| var testProject = env.CreateTestProjectWithFiles(projectContent); | ||
| var logger = new MockLogger(_output); | ||
|
|
||
| var parameters = new BuildParameters | ||
| { | ||
| Loggers = new[] { logger } | ||
| }; | ||
|
|
||
| var result = Helpers.BuildProjectFileUsingBuildManager(testProject.ProjectFile, logger, parameters, targetsToBuild: new[] { "TestTask" }); | ||
|
|
||
| // Build should fail | ||
| result.OverallResult.ShouldBe(BuildResultCode.Failure); | ||
|
|
||
| // Should log MSB4233 error | ||
| logger.ErrorCount.ShouldBeGreaterThan(0); | ||
| logger.Errors[0].Code.ShouldBe("MSB4233"); | ||
baronfel marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Error message should contain the task name and indicate .NET runtime is not supported | ||
| string? errorMessage = logger.Errors[0].Message; | ||
| errorMessage.ShouldNotBeNull(); | ||
| errorMessage.ShouldContain("ProcessIdTask"); | ||
| errorMessage.ShouldContain(".NET runtime"); | ||
| errorMessage.ShouldContain("MSBuild 18.0"); | ||
| } | ||
| #endif | ||
| } | ||
| } | ||
| } | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot fix the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it fails with
src\MSBuild.UnitTests\DotNetRuntimeTask_CLI_Tests.cs(40,76): error CS0234: (NETCORE_ENGINEERING_TELEMETRY=Build) The type or namespace name 'ProcessIdTask' does not exist in the namespace 'Microsoft.Build.UnitTests' (are you missing an assembly reference?)
@copilot
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests currently build successfully. Could you provide more details about what issue needs to be fixed? Are there specific test failures in CI, or specific behavior that needs to be changed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed the compilation error by constructing the assembly path dynamically at runtime instead of using
typeof(ProcessIdTask)which required a compile-time reference. The test now builds the path usingAssembly.GetExecutingAssembly().LocationandPath.Combine. (commit: 3f5d8a1)