Skip to content

Commit e696b07

Browse files
committed
Add another test
1 parent 63abd1a commit e696b07

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

test/Microsoft.NET.Build.Tests/ReferenceExeTests.cs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,66 @@ public void SelfContainedExecutableCannotBeReferencedByNonSelfContainedMTPTestPr
422422
result.Should().HaveStdOutContaining("NETSDK1151").And.ExitWith(1);
423423
}
424424

425+
[Theory]
426+
[CombinatorialData]
427+
public void MTPNonSelfContainedExecutableCannotBeReferencedBySelfContained(bool setIsTestingPlatformApplicationEarly)
428+
{
429+
// The setup of this test is as follows:
430+
// ConsoleApp is a self-contained executable project, which references a non-self-contained MTP executable test project.
431+
// Building ConsoleApp should fail because it references a non-self-contained MTP executable project.
432+
// A non self-contained executable cannot be referenced by a self-contained executable.
433+
var testConsoleProjectSelfContained = new TestProject("ConsoleApp")
434+
{
435+
IsExe = true,
436+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
437+
SelfContained = "true",
438+
};
439+
440+
var testAssetSelfContained = _testAssetsManager.CreateTestProject(testConsoleProjectSelfContained);
441+
442+
var mtpNotSelfContained = new TestProject("MTPTestProject")
443+
{
444+
TargetFrameworks = ToolsetInfo.CurrentTargetFramework,
445+
IsExe = true,
446+
IsTestProject = true,
447+
};
448+
449+
if (setIsTestingPlatformApplicationEarly)
450+
{
451+
mtpNotSelfContained.IsTestingPlatformApplication = true;
452+
}
453+
454+
var testAssetMTP = _testAssetsManager.CreateTestProject(mtpNotSelfContained);
455+
456+
var mtpProjectDirectory = Path.Combine(testAssetMTP.Path, mtpNotSelfContained.Name);
457+
Assert.True(Directory.Exists(mtpProjectDirectory), $"Expected directory {mtpProjectDirectory} to exist.");
458+
Assert.True(File.Exists(Path.Combine(mtpProjectDirectory, "MTPTestProject.csproj")), $"Expected file MTPTestProject.csproj to exist in {mtpProjectDirectory}.");
459+
460+
if (!setIsTestingPlatformApplicationEarly)
461+
{
462+
File.WriteAllText(Path.Combine(mtpProjectDirectory, "Directory.Build.targets"), """
463+
<Project>
464+
<PropertyGroup>
465+
<IsTestingPlatformApplication>true</IsTestingPlatformApplication>
466+
</PropertyGroup>
467+
</Project>
468+
""");
469+
}
470+
471+
var consoleAppDirectory = Path.Combine(testAssetSelfContained.Path, testConsoleProjectSelfContained.Name);
472+
Assert.True(Directory.Exists(consoleAppDirectory), $"Expected directory {consoleAppDirectory} to exist.");
473+
Assert.True(File.Exists(Path.Combine(consoleAppDirectory, "ConsoleApp.csproj")), $"Expected file ConsoleApp.csproj to exist in {consoleAppDirectory}.");
474+
475+
new DotnetCommand(Log, "add", "reference", Path.Combine(testAssetMTP.Path, mtpNotSelfContained.Name))
476+
.WithWorkingDirectory(consoleAppDirectory)
477+
.Execute()
478+
.Should()
479+
.Pass();
480+
481+
var result = new BuildCommand(Log, mtpProjectDirectory).Execute();
482+
result.Should().HaveStdOutContaining("NETSDK1150").And.ExitWith(1);
483+
}
484+
425485
[RequiresMSBuildVersionTheory("17.0.0.32901")]
426486
[InlineData("xunit")]
427487
[InlineData("mstest")]

0 commit comments

Comments
 (0)