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 @@ -35,6 +35,10 @@ Copyright (c) .NET Foundation. All rights reserved.
<DefaultItemExcludes>$(DefaultItemExcludes);$(BaseOutputPath)/**</DefaultItemExcludes>
<!-- obj folder, by default -->
<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>

<!-- Various files that should generally always be ignored -->
<DefaultItemExcludes>$(DefaultItemExcludes);**/*.user</DefaultItemExcludes>
Expand Down
29 changes: 29 additions & 0 deletions test/Microsoft.NET.Build.Tests/GivenThereAreDefaultItems.cs
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,35 @@ public void It_does_not_include_Windows_App_SDK_items_if_Windows_App_SDK_is_abse
.BeEmpty();
}

[Fact]
public void It_excludes_items_in_publish_directory()
{
Action<GetValuesCommand> setup = getValuesCommand =>
{
// Create a PublishDir with a JSON file (simulating a previous publish)
string publishDir = Path.Combine(getValuesCommand.ProjectRootPath, "artifacts", "TestLibrary");
WriteFile(Path.Combine(publishDir, "appsettings.json"),
"{ \"Setting\": \"Value\" }");

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);
propertyGroup.Add(new XElement(ns + "PublishDir", "artifacts\\TestLibrary\\"));
};

var noneItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, _testAssetsManager, "None", setup, projectChanges: projectChanges);

// The appsettings.json file in the PublishDir should not be included in None items
noneItems.Should().NotContain(item => item.Contains("appsettings.json"));
}

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