Reputation: 410
I have created a .NET MAUI Class Library and a ResourceDictionary containing colors inside of it. When I reference it in the local assembly (Class library) it recognizes the color and IntelliSense autocompletes.
However, when trying to reference it in another assembly (class library imported as NuGet package), I can't reference any of the colors inside the dictionary. In the below code, the "ColorsDictionary" line is autocompleted by VS IntelliSense, so the Dictionary is 100% referenced correctly.
<?xml version = "1.0" encoding = "UTF-8" ?>
<Application xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:vewcore="clr-namespace:VewTech.Core.Themes.Colors;assembly=VewTech.Core"
x:Class="MauiApp3.App">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<vewcore:ColorsDictionary/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
When trying to consume resources via DynamicResource or StaticResource from the local project, colors are not autocompleted by VS IntelliSense, and if manually writing them, it throws an exception (resource not found).
Any ideas about what is wrong with my code?
Upvotes: 2
Views: 2327
Reputation: 697
After upgrade from beta 17.3 mac to 17.4 there was on my .cproj file a lot of garbage comparing with a new project file like the following lines:
<ItemGroup>
<MauiXaml Remove="Resources\Colors.xaml" />
<MauiXaml Remove="Resources\Styles.xaml" />
</ItemGroup>
I created a new project and compared the two .cproj files and removed all the garbage and the project build successfully.
I suggest to open the two files and copy paste all you need.
Upvotes: 2
Reputation: 410
It is working now, after reinstalling VS, creating a new project, and importing the package into the new project.
Don't really know why this was happening, I guess it was because of the update (I was using VS2022 Preview and updated to the new release, and this error happened afterward).
Upvotes: 4