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 @@ -38,8 +38,11 @@ Copyright (c) .NET Foundation. All rights reserved.
<!-- 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.
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>
Guard against PublishDir being the project directory (e.g. 'dotnet publish -o .') which would exclude all source files.
Use NormalizeDirectory (not NormalizePath) on both operands so the comparison is trailing-slash insensitive: the CLI
forwards PublishDir as an absolute path with a trailing separator, and NormalizePath preserves the input's trailing
slash, so NormalizePath would treat 'C:\proj\' and 'C:\proj' as different and re-introduce the exclusion. -->
<DefaultItemExcludes Condition="'$(PublishDir)' != '' And '$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory), $(PublishDir)))' != '$([MSBuild]::NormalizeDirectory($(MSBuildProjectDirectory)))'">$(DefaultItemExcludes);$(PublishDir)/**</DefaultItemExcludes>

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

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", ".\\"));
// PublishDir set to the absolute project directory with an OS-appropriate trailing separator.
// This is exactly what the CLI forwards for 'dotnet publish -o .' (see
// OptionExtensions.ForwardAsOutputPath, which calls GetFullPath and appends a
// directory separator), and is the value that regressed in dotnet/sdk#55295.
// EnsureTrailingSlash yields the platform-correct separator so the test matches CLI behavior on all platforms.
propertyGroup.Add(new XElement(ns + "PublishDir", "$([MSBuild]::EnsureTrailingSlash($(MSBuildProjectDirectory)))"));
};

var compileItems = GivenThatWeWantToBuildALibrary.GetValuesFromTestLibrary(Log, TestAssetsManager, "Compile", setup, projectChanges: projectChanges);
Expand Down
Loading