5

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

David Pugh
  • 758
  • 3
  • 12
  • 33
  • 2
    This question is related to this issue [The name 'Resources' is reserved and cannot be used. #10531](https://github.com/dotnet/maui/issues/10531) Please have a look if it could help. – Liqun Shen-MSFT Oct 25 '22 at 02:15

2 Answers2

1

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

David Pugh
  • 758
  • 3
  • 12
  • 33
0

I have the same error from new MAUI project (No Razor) on VS for Mac v17.4.4: The name 'Resources' is reserved and cannot be used.

What I did was:

  1. Edit "ProjectName.csproj" and change all references to folder "Resources" and renamed to "ResourcesNet" Edited ProjectName.csproj
  2. Change the folder name from "Resources" to "ResourcesNet"
  3. Change in App.xaml all references to "Resources" to "ResourcesNet" Edited folder name and App.xaml
Carlos Borges
  • 81
  • 1
  • 4