[英]Visual Studio for Mac 17.4.3 can't build .NET MAUI project
[英]Can't add images to new .NET MAUI project on Mac without getting: The name 'Resources' is reserved and cannot be used
我剛剛在我的 Mac 上啟動了一個全新的模板 .NET MAUI 項目,我能夠毫無問題地構建和運行啟動項目。 當我將任何圖像添加到“Resources/Images”文件夾,然后嘗試構建項目時,出現錯誤:
錯誤描述:名稱“Resources”已保留,無法使用。
錯誤路徑: Resources/Images/icon_notes.png
規格 Visual Studio for Mac 17.4 預覽版(17.4 內部版本 2326)
我曾嘗試清理和重建項目,但這無濟於事。
重現步驟:
請幫助我了解這里出了什么問題以及如何解決它。
這是我的 csproj 文件
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0-android;net6.0-ios;net6.0-maccatalyst</TargetFrameworks>
<TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net6.0-windows10.0.19041.0</TargetFrameworks>
<!-- Uncomment to also build the tizen app. You will need to install tizen by following this: https://github.com/Samsung/Tizen.NET -->
<!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> -->
<OutputType>Exe</OutputType>
<RootNamespace>Notes</RootNamespace>
<UseMaui>true</UseMaui>
<SingleProject>true</SingleProject>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Display name -->
<ApplicationTitle>Notes</ApplicationTitle>
<!-- App Identifier -->
<ApplicationId>com.companyname.notes</ApplicationId>
<ApplicationIdGuid>2cc957c4-bc4d-4867-9002-8475070561fa</ApplicationIdGuid>
<!-- Versions -->
<ApplicationDisplayVersion>1.0</ApplicationDisplayVersion>
<ApplicationVersion>1</ApplicationVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion>
<TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion>
<SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion>
</PropertyGroup>
<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />
<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />
<!-- Images -->
<MauiImage Include="Resources\Images\*" />
<MauiFont Include="Resources\Fonts\*" />
<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>
</Project>
這是導致此問題的圖像屬性:
感謝 Liqun Shen 對解決方案的指導。
問題是,當您將圖像添加到 Resources/Images 文件夾並檢查您的 csproj 文件時,您會看到每個圖像都作為 ItemGroup 添加到 csproj 文件中。 這一定是某種錯誤,解決方案是從 csproj 文件中手動刪除它們,然后代碼構建並正常運行。 我知道在我的 csproj 文件中,我列出了這些 ItemGroups,因為每個添加的圖像都沒有顯示,但再次檢查它們是否存在並刪除它們解決了我的問題。 在我添加圖像之前,我一定是從我嘗試擦除我的項目並再次重試的一次嘗試中復制了我的 csproj 文件。
<ItemGroup>
<None Remove="Resources\Images\icon_notes.png" />
</ItemGroup>
這是 Liqun Shen 發布的描述此內容的鏈接: https://github.com/do.net/maui/issues/10531
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.