Skip to content
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 @@ -37,8 +37,9 @@ Copyright (c) .NET Foundation. All rights reserved.
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseIntermediateOutputPath)/**</DefaultItemExcludes>
<!-- Exclude PublishDir to prevent published artifacts from being included in subsequent builds/publishes.
While in most cases PublishDir is contained within BaseOutputPath or BaseIntermediateOutputPath,
this is by no means required, so we should protect against this happening here. -->
<DefaultItemExcludes Condition="'$(PublishDir)' != ''">$(DefaultItemExcludes);$(PublishDir)/**</DefaultItemExcludes>
this is by no means required, so we should protect against this happening here.
Guard against PublishDir being the project directory (e.g. 'dotnet publish -o .') which would exclude all source files. -->
<DefaultItemExcludes Condition="'$(PublishDir)' != '' And '$([MSBuild]::NormalizePath($(MSBuildProjectDirectory), $(PublishDir)))' != '$([MSBuild]::NormalizePath($(MSBuildProjectDirectory)))'">$(DefaultItemExcludes);$(PublishDir)/**</DefaultItemExcludes>

<!-- Various files that should generally always be ignored -->
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.user</DefaultItemExcludes>
Expand Down
26 changes: 26 additions & 0 deletions test/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,32 @@ public void It_excludes_items_in_publish_directory()
noneItems.Should().NotContain(item => item.Contains("appsettings.json"));
}

[Fact]
public void It_does_not_exclude_source_files_when_publish_dir_is_project_root()
{
Action<GetValuesCommand> setup = getValuesCommand =>
{
WriteFile(Path.Combine(getValuesCommand.ProjectRootPath, "Code", "Class1.cs"),
"public class Class1 {}");
};

Action<XDocument> projectChanges = project =>
{
var ns = project.Root.Name.Namespace;

var propertyGroup = new XElement(ns + "PropertyGroup");
project.Root.Add(propertyGroup);
// PublishDir set to the project directory itself (simulates 'dotnet publish -o .')
propertyGroup.Add(new XElement(ns + "PublishDir", ".\\"));
Comment thread
jjonescz marked this conversation as resolved.
};

var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "Compile", setup, projectChanges: projectChanges);

RemoveGeneratedCompileItems(compileItems);

compileItems.Should().BeEquivalentTo(new[] { Path.Combine("Code", "Class1.cs"), "Helper.cs" });
}

void RemoveGeneratedCompileItems(List<string> compileItems)
{
// Remove auto-generated compile items.
Expand Down
Loading