7

I can't get rid of this build error in my .net maui app in Visual Studio for Mac 2022 v17? The build output says:

/usr/local/share/dotnet/packs/Microsoft.Maui.Resizetizer.Sdk/6.0.300-rc.3.5667/targets/Microsoft.Maui.Resizetizer.targets(511,9): error :             One or more invalid file names were detected.  File names must be lowercase, start and end with a letter character, and contain only alphanumeric characters or underscores: 

When I copied the image files into the resource/image folder they did have invalid characters, but I renamed the files to only have valid lowercase alpha numeric letters but still visual studio is just broken. I've cleaned the project, manually deleted bin and obj folders, restarted the solution and visual studio and even booted the whole machine with no success. I've even tried to delete all images but no luck.

There must be some other cache that is still holding invalid references of the error message is simply wrong and is thrown for some other related reason. Any help finding this issues would be greatly appreciated.

Edit I have now created a new project (MyMauiSolution) and one by one copied the folders from the old solution to see where it would break. After all files are coped into the new project it still works. So now I have 2 solutions with more or less exactly the same files/images, where one is working and the other is not?!

I have even tried diffing the folder structures, but there are no differences?!

myiMac:Projects user_x$ diff -rq BlueWhaleMaui MyMauiSolution
Files BlueWhaleMaui/.DS_Store and MyMauiSolution/.DS_Store differ
Only in BlueWhaleMaui: .git
Only in BlueWhaleMaui: .gitignore
Only in BlueWhaleMaui: BlueWhaleMaui
Only in MyMauiSolution: MyMauiApp
Cliffhanger
  • 1,057
  • 1
  • 9
  • 18
  • Simplest fix is to create a new project. Copy stuff over gradually. Other ideas: `.vs` hidden folder. `.csproj` itself. If you hadn't deleted all the images, I'd say to check each one's `Properties`, to see if it is remembering original filename with invalid characters. – ToolmakerSteve May 30 '22 at 01:47
  • Hi! Nothing in .vs or what i can find in .csproj. I've even tried to go back in the git history to well before adding the invalid filenames. – Cliffhanger May 30 '22 at 06:12
  • Tried the suggestion with a new project and no change (See the edit in the main post) – Cliffhanger May 30 '22 at 14:41
  • Maybe https://stackoverflow.com/a/49848189/199364 – ToolmakerSteve May 30 '22 at 17:15
  • 2
    Not sure this will work for all but, out of frustration for not finding the diffing file/data between the two projects, I copied in all files/folders from MyMauiSolution to the BlueWhaleMaui project, in effect writing over all files in the solution... ...and now it works again. As the mac diff operation also lists internal file differences, I can't tell what was wrong but perhaps some lock/cache released when updating the files. – Cliffhanger May 31 '22 at 05:43
  • I agree with @Cliffhanger. I got frustrated trying to figure out what was wrong. This is the second time happening to me. I created another project moved my files and it's working again. – D. Kermott Aug 03 '22 at 20:15
  • getting same issue – Suchith Sep 27 '22 at 09:40

3 Answers3

20

This is likely caused by the existence of a hidden file in the Resources\Images directory created by the Mac operating system when using the Finder to manipulate files in that directory. (.DS_store)

The .DS_store is not visible in Finder even when 'Show All Files' is turned on, so to confirm:

  1. Open the Terminal application
  2. Change to your project's Resources\Images directory
  3. Perform the command 'ls -la' in the Resources\Images directory
  4. Confirm the existence of the '.DS_store' file (or any other 'dot' file)

There are two solutions (one a workaround, really)

  • Simply use the Terminal application window to delete the file
  • Edit your project (csproj) file to exclude the .DS_store from resizing

If you delete the file using terminal the issue will return the next time you use Finder to manipulate files in that folder/directory.

Alternatively, open your project (csproj) file and find the section that defines the MauiImage resources in your project. It should look something like this :<MauiImage Include="Resources\Images\* />

Change that from a single wildcard to a list of more specific patterns to include:

<MauiImage Include="Resources\Images\*svg />
<MauiImage Include="Resources\Images\*png />
<MauiImage Include="Resources\Images\*jpg />

This should include only files ending in these image-type file extensions in the resizing process and skipping the .DS_store file.

Tim Reynolds
  • 216
  • 1
  • 3
5

I had the same problem. As a workaround I deleted 'Images' folder (after backed up), create a new 'Images' folder and restore the images.

0

Problem resolved by removing .DS_Store file. This include all the sub-folder.