-
Notifications
You must be signed in to change notification settings - Fork 6k
Description
Generating errors for duplicate files in publish output
We added a new error (NETSDK1148) in cases where files from different source paths would be copied to the same file path in the publish output. This can happen when a project and its project references include a file with the same name that is included in the publish output.
dotnet/sdk#10850
dotnet/sdk#14020
Version introduced
6.0.100-preview1
Old behavior
Both files would be copied to the same destination. The second one would overwrite the first one, so which file "won" was mostly arbitrary.
In some cases, the build would fail, for example when trying to create a single-file app the bundler would fail with an ArgumentException:
C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: The "GenerateBundle" task failed unexpectedly. [C:\repro\repro.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: System.ArgumentException: Invalid input specification: Found multiple entries with the same BundleRelativePath [C:\repro\repro.csproj]
C:\Program Files\dotnet\sdk\5.0.100-preview.5.20258.6\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Publish.targets(962,5): error MSB4018: at Microsoft.NET.HostModel.Bundle.Bundler.GenerateBundle(IReadOnlyList`1 fileSpecs) [C:\repro\repro.csproj]
New behavior
We remove duplicate files copied to the publish folder if both the source and destination are the same. If there are any remaining duplicates, we generate a NETSDK1148 error, listing the files which are duplicated.
Reason for change
Duplicate files in the publish output were sometimes causing build breaks and in other situations causing unpredictable behavior.
Recommended action
Ideally, projects should be updated to avoid situations where multiple files with the same name will be copied to the publish output.
Additionally, the following property can be set to suppress the check for duplicate files:
<ErrorOnDuplicatePublishOutputFiles>false</ErrorOnDuplicatePublishOutputFiles>
Category
- ASP.NET Core
- C#
- Code analysis
- Core .NET libraries
- Cryptography
- Data
- Debugger
- Deployment
- Globalization
- Interop
- JIT
- LINQ
- Managed Extensibility Framework (MEF)
- MSBuild
- Networking
- Printing
- Security
- Serialization
- [ x] SDK
- Visual Basic
- Windows Forms
- Windows Presentation Foundation (WPF)
- XML, XSLT
Affected APIs
"Not detectable via API analysis"
Issue metadata
- Issue type: breaking-change