-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Description
Description
After migrating our MAUI app from net7.0 to net8.0, we started seeing the following build error:
One or more duplicate file names were detected. All image output filenames must be unique.
This error is described in this MAUI known issues doc in a section titled Duplicate image filename errors.
However, the error is not caused by the scenario described in that doc. Instead, the duplicate image file errors in our app are being generated for image files that are included in NuGets we are importing into our app. The image files were added to the NuGets using a technique suggested by the MAUI team in this MAUI net7.0 issue.
Steps to Reproduce
To verify that this error wasn't due to some idiosyncrasy of our app, we created two test solutions using the VS new project wizard to reproduce the issue. The test solutions (found at the public repro project repo link below) consist of the following:
TestMauiImageNuGet.sln: This contains a single project named TestMauiImageNuGet. This was used to create a NuGet containing a single .svg image.
MauiDupImageTestApp.sln: This contains two projects. DoNothingAppLib1.csproj is a library project that contains a reference to the TestMauiImageNuGet NuGet. MauiDupImageTestApp.csproj is the main app project that is simply the standard "Hello, World!" app generated by the VS app wizard for net8.0. The app has a reference to the DoNothingAppLib1 project.
To summarize, the test code consists of a main app (MauiDupImageTestApp) that references a library (DoNothingAppLib1), which in turn references a NuGet (TestMauiImageNuGet) that contains an .svg image file.
Before attempting to build the app, you'll first need to add the test code's LocalNuGetRepo folder to your NuGet package sources. In Visual Studio, this is done as follows:
- Select "Tools" > "NuGet Package Manager" > "Package Manager Settings"
- Select "Package Sources"
- Click the "+" button
- Set the name to "DupImageTestSource" and the Source to full folder path to the test code's "LocalNuGetRepo" folder.
Once that is done, build the MauiDupImageTestApp.sln. If the error described here exists, the build will fail due to the "All image output filenames must be unique" error.
There are no actual references to the image in the NuGet in the code of either the DoNothingAppLib1 or the TestMauiImageNuGet projects. Merely including the NuGet with the image is enough to trigger the "duplicate file names" error.
This issue does not occur in the test projects if the target platforms are changed from net8.0 to net7.0. So clearly, this was introduced by the changes made for net8.0.
The test projects only target Android and iOS because those are the platforms we target in our MAUI apps.
Suggestion
The duplicate image files being detected are in fact multiple references to the same image file. If that's the case, and the reason for having a duplicate filename check for image files in the build process is to ensure that one image isn't overwritten by a different image, then adding a binary comparison to determine if the "duplicate" files are really different files would eliminate the error for this scenario.
Link to public reproduction project repository
https://github.com/awalker-dsg/Net8_Dup_Image_Issue
Version with bug
8.0.3
Is this a regression from previous behavior?
Yes, this used to work in .NET MAUI
Last version that worked well
Unknown/Other
Affected platforms
iOS, Android
Affected platform versions
This is a build error, not a runtime error. It may occur on other platforms, but we only target iOS and Android.
Did you find any workaround?
Adding ExcludeAssets="buildTransitive" to the NuGet PackageReference in a solution's library projects eliminates the build error. This workaround should not be applied to NuGets included in projects whose OutputType is Exe because otherwise the app will not be able to access the images.
An example of this workaround can be found in commented-out code in the repro code's DoNothingAppLib1.csproj project.
The workaround gets us past the build error. However, it requires developers to manually edit the .csproj files after adding NuGets that contain image references to their projects. In our case, the NuGets are usually added using the VS NuGet Package Manger, so the need for this workaround usually won't be known until developers get "duplicate file names" errors during the next build. And, unless the developer is already familiar with the error, they will likely waste time trying to figure out what broke the build before finding a reference to the workaround. This is less than ideal.
Relevant log output
2>C:\Users\xxxx\.nuget\packages\microsoft.maui.resizetizer\8.0.3\buildTransitive\Microsoft.Maui.Resizetizer.After.targets(619,9): error : One or more duplicate file names were detected. All image output filenames must be unique: test_image_arrow (C:\Users\xxxx\.nuget\packages\testmauiimagenuget\8.0.0\buildTransitive\\Images\test_image_arrow.svg)
2>Done building project "MauiDupImageTestApp.csproj" -- FAILED.
2>C:\Users\xxxx\.nuget\packages\microsoft.maui.resizetizer\8.0.3\buildTransitive\Microsoft.Maui.Resizetizer.After.targets(619,9): error : One or more duplicate file names were detected. All image output filenames must be unique: test_image_arrow (C:\Users\xxxx\.nuget\packages\testmauiimagenuget\8.0.0\buildTransitive\\Images\test_image_arrow.svg)
2>Done building project "MauiDupImageTestApp.csproj" -- FAILED.