Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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 @@ -1414,7 +1414,7 @@ public static void WriteProjectFile(

writer.WriteLine($"""
<ItemGroup>
<Compile Include="{EscapeValue(targetFilePath)}" />
<Compile Condition="'$(EnableDefaultCompileItems)'!='true'" Include="{EscapeValue(targetFilePath)}" />
</ItemGroup>

""");
Expand Down
28 changes: 26 additions & 2 deletions test/dotnet.Tests/CommandTests/Run/RunFileTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,32 @@ public void MultipleFiles_RunEntryPoint()
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should().Pass()
// warning CS2002: Source file 'Program.cs' specified multiple times
.And.HaveStdOutContaining("warning CS2002")
.And.NotHaveStdOutContaining("warning CS2002")
.And.HaveStdOutContaining("Hello, String from Util");
}

/// <summary>
/// Setting EnableDefaultCompileItems=true via Directory.Build.props should not cause CS2002 warning.
/// </summary>
[Fact]
public void MultipleFiles_EnableDefaultCompileItemsViaDirectoryBuildProps()
{
var testInstance = _testAssetsManager.CreateTestDirectory();
File.WriteAllText(Path.Join(testInstance.Path, "Program.cs"), s_programDependingOnUtil);
File.WriteAllText(Path.Join(testInstance.Path, "Util.cs"), s_util);
File.WriteAllText(Path.Join(testInstance.Path, "Directory.Build.props"), """
<Project>
<PropertyGroup>
<EnableDefaultCompileItems>true</EnableDefaultCompileItems>
</PropertyGroup>
</Project>
""");

new DotnetCommand(Log, "run", "Program.cs")
.WithWorkingDirectory(testInstance.Path)
.Execute()
.Should().Pass()
.And.NotHaveStdOutContaining("warning CS2002")
.And.HaveStdOutContaining("Hello, String from Util");
}

Expand Down
Loading