Search code examples
visual-studio.net-maui

Can't add images to new .NET MAUI project on Mac without getting: The name 'Resources' is reserved and cannot be used


I just started a brand new template .NET MAUI project on my Mac and I am able to build and run the startup project with no problems. When I add any image to the "Resources/Images" folder and then try to build the project I get the error:

Error Description: The name 'Resources' is reserved and cannot be used.

Error Path: Resources/Images/icon_notes.png

SPECS Visual Studio for Mac 17.4 Preview (17.4 build 2326)

I have tried cleaning and rebuilding the project but that does not help.

Steps to reproduce:

  1. Install Visual Studio for Mac 17.4 Preview
  2. Create new .NET MAUI project from startup template offered by the IDE
  3. Build and run to make sure it runs properly (It will).
  4. Add any image to the "Resources/Images" folder and then try to rebuild.

Please help me understand what is wrong here and how to fix it.

Here is my csproj file

<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>

Here is the properties on the image that is causing this:

enter image description here


Solution

  • Thanks to Liqun Shen for the direction to the solution.

    The issue is that when you add an image to the Resources/Images folder and check your csproj file you will see that each image is added as an ItemGroup to the csproj file. This must be some sort of bug and the solution was to manually delete these from the csproj file after which the code builds and runs properly. I know that in my csproj file I listed about these ItemGroups for each image added wasn't showing but checking again they were there and removing them fixed my issue. I must have copied my csproj file from one of my attempts at erasing my project and retrying again and before I added the image.

    <ItemGroup>
          <None Remove="Resources\Images\icon_notes.png" />
    </ItemGroup>
    

    Here is the link that Liqun Shen posted that describes this: https://github.com/dotnet/maui/issues/10531