After updating to .net8, reference the System.Windows.Controls in the xaml editor
Asked Answered
S

1

7

The .NET RID changed from .NET8, so I modified the PropertyGroup in the csproj file as follows.

<PropertyGroup>
  <OutputType>WinExe</OutputType>
  <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
  <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
  <RootNamespace>Test</RootNamespace>
  <ApplicationManifest>app.manifest</ApplicationManifest>
  <Platforms>x64</Platforms>
  <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
  <PublishProfile>win-$(Platform).pubxml</PublishProfile>
  <UseWinUI>true</UseWinUI>
  <EnableMsixTooling>true</EnableMsixTooling>
</PropertyGroup>

I also modified the name and rid of the pubxml file.

After that, in the xaml editor, it initially normally referenced Microsoft.UI.Xaml.Controls namespace, but at some point, without knowing why, the error occurred by referencing the System.Windows.Controls namespace, and auto-completion did not work.

enter image description here

enter image description here

The error is not described, but by mouse-up and looking at the type of Grid, you can see that it is "System.Windows.Controls.Grid."

When I compile it, it works normally, but it's difficult to code due to bugs in the editor.

Does anyone know why this bug is happening?

Simson answered 18/11, 2023 at 9:2 Comment(2)
I don't have that problem with similar csproj have you updated the latest WinAPP SDK (1.4.231115000) and build tools (10.0.22621.2428)? Also can you try to close Visual Studio, delete bin & obj directories and re-openBorreri
@SimonMourier It's all the latest versions, and I've tried the methods you've suggested, but they still get bugs. I didn't get a bug at first, but it happens sometime when I code.Simson
S
20

UPDATE

The workaround UseRidGraph is no longer required from WindowsAppSDKv1.4.4.


The are the steps that works for me to upgrade from .NET 7 to .NET 8:

  1. Install .NET 8 SDK.

  2. Edit your *.csproj file.

    • TargetFramework: net8.0-windows10.0.19041.0
    • RuntimeIdentifiers: win-x86;win-x64;win-arm64
    • PublishProfile: win-$(Platform).pubxml
    • Add UseRidGraph and set it to true.

    For example:

    <PropertyGroup>
      <OutputType>WinExe</OutputType>
      <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
      <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
      <RootNamespace>WinUI3App4</RootNamespace>
      <ApplicationManifest>app.manifest</ApplicationManifest>
      <Platforms>x86;x64;ARM64</Platforms>
      <RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
      <PublishProfile>win-$(Platform).pubxml</PublishProfile>
      <UseRidGraph>true</UseRidGraph>
      <UseWinUI>true</UseWinUI>
      <EnableMsixTooling>true</EnableMsixTooling>
      <Nullable>enable</Nullable>
    </PropertyGroup>
    

These steps might be changed in later versions of WindowsAppSDK. Check this from the release notes.

Stinger answered 18/11, 2023 at 13:8 Comment(1)
That's such a shame to Mictosoft that WinUI projects just cannot be even compiled "out-of-the-box" without tuning ups! That greatly shows Microsoft attitude its Desktop infrastructure!Aylmar

© 2022 - 2024 — McMap. All rights reserved.