Skip to content

Don't produce errors when an Exe project references a test project #18986

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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -1051,13 +1051,19 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- Don't generate a NETSDK1151 error if a non self-contained Exe references a Blazor wasm Exe -->
<ShouldBeValidatedAsExecutableReference>false</ShouldBeValidatedAsExecutableReference>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true' And '$(ValidateExecutableReferencesMatchSelfContained)' == ''">
<!-- Don't generate an error if a test project references a self-contained Exe. Test projects
use an OutputType of Exe but will usually call APIs in a referenced Exe rather than try
to run it. -->
<ValidateExecutableReferencesMatchSelfContained>false</ValidateExecutableReferencesMatchSelfContained>
</PropertyGroup>

<PropertyGroup Condition="'$(IsTestProject)' == 'true'">
<!-- Don't generate an error if an Exe project references a test project. -->
<ShouldBeValidatedAsExecutableReference>false</ShouldBeValidatedAsExecutableReference>
</PropertyGroup>


<UsingTask TaskName="ValidateExecutableReferences" AssemblyFile="$(MicrosoftNETBuildTasksAssembly)" />

Expand Down
37 changes: 37 additions & 0 deletions src/Tests/Microsoft.NET.Build.Tests/ReferenceExeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,5 +295,42 @@ public void TestProjectCanReferenceExe(string testTemplateName)
.Pass();

}

[RequiresMSBuildVersionTheory("17.0.0.32901")]
[InlineData("xunit")]
[InlineData("mstest")]
public void ExeProjectCanReferenceTestProject(string testTemplateName)
{
var testConsoleProject = new TestProject("ConsoleApp")
{
IsExe = true,
TargetFrameworks = "net6.0",
RuntimeIdentifier = EnvironmentInfo.GetCompatibleRid()
};

var testAsset = _testAssetsManager.CreateTestProject(testConsoleProject, identifier: testTemplateName);

var testProjectDirectory = Path.Combine(testAsset.TestRoot, "TestProject");
Directory.CreateDirectory(testProjectDirectory);

new DotnetCommand(Log, "new", testTemplateName)
.WithWorkingDirectory(testProjectDirectory)
.Execute()
.Should()
.Pass();

string consoleProjectDirectory = Path.Combine(testAsset.Path, testConsoleProject.Name);

new DotnetCommand(Log, "add", "reference", ".." + Path.DirectorySeparatorChar + "TestProject")
.WithWorkingDirectory(consoleProjectDirectory)
.Execute()
.Should()
.Pass();

new BuildCommand(Log, consoleProjectDirectory)
.Execute()
.Should()
.Pass();
}
}
}