0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

MAUI Tips - 突然発生するResizetizeImagesのビルドエラー

Posted at

概要

これまでXamarin.Formsで作っていたアプリを、一念発起して.NET MAUIで作り直す中で
調べたことの備忘録。

環境

Visual Studio for MAC
.NET MAUI
.NET 7

現象

画像ファイルの追加作業などの後にビルドしたら、急に以下のようなエラーが表示されてしまいました。
image.png

ビルド出力を確認すると、以下のようなメッセージが表示されていました。

ターゲット ResizetizeImages:
        /usr/local/share/dotnet/packs/Microsoft.Maui.Resizetizer.Sdk/7.0.92/targets/Microsoft.Maui.Resizetizer.targets(525,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: 
    

エラーメッセージの内容を見る限り、ファイル名の命名規則に反したファイルがあるとのこと。
ターゲットがResizetizeImagesとなっており、Imagesフォルダのファイル名のようなんですが、
全て英小文字とアンダースコアで構成されるファイル名で、命名規則には反していませんでした・・・。

追加したファイルを削除しても、エラーが取り除かれず・・・。

原因

.NET MAUIのGitHubのIssueページに、参考になる情報が掲載されてました。

Imagesフォルダでファイルの追加や削除などをしていると、
macOSが自動的に「.DS_Store」というファイルを生成するらしく、
それがビルドエラーを引き起こす原因となっているとのこと。

.DS_Storeがあるかは、ターミナルでカレントフォルダを該当フォルダにした後に、
以下のコマンドを実行すると確認できます。

>ls -a

.DS_Storeファイルが隠しファイルなので、Finder上で見えませんでした。
なので、このファイルのせいだとか、なかなか気づけないですよね・・・。

対処方法

ターミナルでカレントフォルダを該当フォルダにした後に、
以下のコマンドを実行すれば、.DS_Storeファイルを削除できます。

>rm .DS_Store

もう一つの方法として、プロジェクトファイルの中にある、Imagesフォルダ内のファイルを
全部取り込む記述に、例外ファイルを指定するやり方があるとのこと。
以下のように、Excludeオプションで.DS_Storeファイルを指定します。

		<!-- Images -->
		<MauiImage Include="Resources\Images\*" Exclude="Resources\Images\.DS_Store"/>

.DS_Storeファイルの生成タイミングがわからないし、
いちいち削除するのも面倒なので、Excludeオプションを使う方が楽そうですね。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?