CommunityToolkit / Windows

Collection of controls for WinUI 2, WinUI 3, and Uno Platform developers. Simplifies and demonstrates common developer tasks building experiences for Windows with .NET.
https://aka.ms/windowstoolkitdocs
Other
590 stars 74 forks source link

Undefined namespace XAML #533

Closed happer64bit closed 1 month ago

happer64bit commented 1 month ago

Describe the bug

I am using WinUI 3 and I can't import SettingsCard in XAML code. All Packages are downloaded and I have tired both 8.1 and 8.0 but no luck.

Severity    Code    Description Project File    Line    Suppression State   Details
Error   XLS0429 Undefined namespace. The 'using' URI refers to a namespace 'CommunityToolkit.WinUI.Controls' that could not be found.   name C:\Users\dev\Projects\name\name\MainWindow.xaml    9       
<?xml version="1.0" encoding="utf-8"?>
<Window
    x:Class="name.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:name"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:control="using:CommunityToolkit.WinUI"
    mc:Ignorable="d">

    <StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
        <controls:SettingsCard x:Name="settingsCard"
                               Description="This is a default card, with the Header, HeaderIcon, Description and Content set."
                               Header="This is the Header"></controls:SettingsCard>
    </StackPanel>
</Window>
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>name</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;ARM64</Platforms>
    <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &gt;= 8">win-x86;win-x64;win-arm64</RuntimeIdentifiers>
    <RuntimeIdentifiers Condition="$([MSBuild]::GetTargetFrameworkVersion('$(TargetFramework)')) &lt; 8">win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
  </PropertyGroup>

  <ItemGroup>
    <Content Include="Assets\SplashScreen.scale-200.png" />
    <Content Include="Assets\LockScreenLogo.scale-200.png" />
    <Content Include="Assets\Square150x150Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.scale-200.png" />
    <Content Include="Assets\Square44x44Logo.targetsize-24_altform-unplated.png" />
    <Content Include="Assets\StoreLogo.png" />
    <Content Include="Assets\Wide310x150Logo.scale-200.png" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="CommunityToolkit.WinUI.Controls.SettingsControls" Version="8.1.240916" />
    <PackageReference Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.22621.756" />
    <PackageReference Include="Microsoft.WindowsAppSDK" Version="1.6.240923002" />
    <Manifest Include="$(ApplicationManifest)" />
  </ItemGroup>

  <!--
    Defining the "Msix" ProjectCapability here allows the Single-project MSIX Packaging
    Tools extension to be activated for this project even if the Windows App SDK Nuget
    package has not yet been restored.
  -->
  <ItemGroup Condition="'$(DisableMsixProjectCapabilityAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
    <ProjectCapability Include="Msix" />
  </ItemGroup>

  <!--
    Defining the "HasPackageAndPublishMenuAddedByProject" property here allows the Solution
    Explorer "Package and Publish" context menu entry to be enabled for this project even if
    the Windows App SDK Nuget package has not yet been restored.
  -->
  <PropertyGroup Condition="'$(DisableHasPackageAndPublishMenuAddedByProject)'!='true' and '$(EnableMsixTooling)'=='true'">
    <HasPackageAndPublishMenu>true</HasPackageAndPublishMenu>
  </PropertyGroup>
</Project>

Steps to reproduce

Just click run

Expected behavior

to Import CommunityToolkit.WinUI.Controls.SettingsCard with any error

Screenshots

Image

Code Platform

Windows Build Number

Other Windows Build number

No response

App minimum and target SDK version

Other SDK version

10.0.17763.0

Visual Studio Version

2022

Visual Studio Build Number

17.11.5

Device form factor

Desktop

Additional context

No response

Help us help you

No, I'm unable to contribute a solution.

happer64bit commented 1 month ago

Just roll back from 8.1 to 8.0. It will work

Arlodotexe commented 1 week ago

This may help. From our blog post regarding 8.1:

When consuming the Toolkit, you must target Windows version 22621 instead of the prior 18362, i.e. if you were targeting net6.0-windows10.0.18362, you would target net6.0-windows10.0.22621 instead now.

This does not affect your ability to run down-level with the minimum target version, that remains at 17763.

Try updating your TFM and see if that helps.