Hello @dg2k ,
Thanks for your reply.
Your reply provides the key information => .NET MAUI project.
In short:
In your .csproj file, add <EnableDefaultNoneItems>false</EnableDefaultNoneItems>
in property group.
Long story:
I tested the usual web project before and the situation is quite different when I tested in .NET MAUI project. The issue you got should be a new behavior of new SDK style projects or Maui projects.
The key is the setting in this file => C:\Program Files\dotnet\packs\Microsoft.Maui.Sdk\6.0.548\Sdk\Microsoft.Maui.Controls.DefaultItems.targets. This file is pointed in the detailed error message(the path maybe a little different). If you open the Microsoft.Maui.Controls.DefaultItems.targets
file, you can see following ItemGroup:
<ItemGroup Condition="'$(EnableDefaultItems)'=='True' And '$(EnableDefaultCssItems)'=='True' And '$(EnableDefaultEmbeddedResourceItems)'=='True'">
<None Remove="**\*.css" Condition="'$(EnableDefaultNoneItems)'=='True'" />
</ItemGroup>
When the condition is true, the ***.css file will be removed. So, let’s focus on $(EnableDefaultNoneItems)
. Here’s the description: EnableDefaultNoneItems.
The EnableDefaultNoneItems property controls whether None items (files that have no role in the build process) are implicitly included in the project. The default value is true. Set the EnableDefaultNoneItems property to false to disable implicit inclusion of None items.
Apparently, when we changed the Build Action to None, the .css file will be removed(excluded) from the Maui project and then the error appears => One or more values are invalid. Cannot add ..css
to the project, because the path is explicitly excluded from the project.
If you open the project file(.csproj), you can see there’s a new Item group added to remove the .css file and there’s no property settings for EnableDefaultNoneItems property. The EnableDefaultNoneItems property is set to true by default. So the solution is easy, add following line as a property to your .csproj file and you can successfully change the Build Action to None.
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
Have a great day.
Sincerely,
Tianyu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.