範例訊息
error XA1041: The MSBuild property 'MonoAndroidAssetPrefix' has an invalid value of 'c:\Foo\Assets'. The value is expected to be a directory path representing the relative location of your Assets or Resources.
error XA1041: The MSBuild property 'MonoAndroidResourcePrefix' has an invalid value of 'c:\Foo\Resources'. The value is expected to be a directory path representing the relative location of your Assets or Resources.
Issue
問題在於 MonoAndroidAssetPrefix 和 MonoAndroidResourcePrefix 都預期是相對的目錄路徑。 這些資訊用來在我們打包應用程式時,將根目錄資訊從資產或資源中「剝離」出來。
錯誤之所以會被提出,是因為該性質包含一條完整的路徑。
例如,考慮以下結構:
Foo.csproj
MyAssets/
Foo.txt
Subfolder/
Bar.txt
MainActivity.cs
在最終的.apk階段,我們期望檔案Foo.txt和Bar.txt會被放入assets資料夾中。 為了正確執行這件事,建置系統需要知道資產所在資料夾的名稱。 預設是「資產」,但也支援其他資料夾名稱。
在上述範例中,我們預期使用者會設定 MonoAndroidAssetPrefix 為「MyAssets」的值。 這樣可以確保在包裝過程中移除通往「Foo.txt」等路徑中的「MyAssets」部分。 如果MonoAndroidAssetPrefix設定為/Users/xxx/Foo/MyAssets或c:\Users\xxx\Foo\MyAssets,你會看到這個錯誤訊息。
解決方案
解決方法是不要為 MonoAndroidAssetPrefix 或 MonoAndroidResourcePrefix 的值使用完整路徑。 它們應該是相對的目錄路徑,與你資產存放的資料夾路徑相符。