The type or namespace name 'Management' does not exist in the namespace 'Windows’
🚦

The type or namespace name 'Management' does not exist in the namespace 'Windows’

Published
September 25, 2023
Author
WuZheng

背景

UE 引擎编译时,HoloLens.Automation 报错 The type or namespace name 'Management' does not exist in the namespace 'Windows’
notion image
报错提示也很明显,需要检查是否缺少依赖库的引用。该库是 Windows SDK 中的,让我们先来检查引用。

检查引用

notion image
notion image
 
我的电脑上并不存在 C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd 这个路径,可见引用确实不对。

方案一:手动重置引用【不推荐】

  1. Windows 程序集上右键并移除引用,不移除引用无法重新添加
  1. HoloLens.Automation 右键 → Add → Reference…
    1. notion image
  1. 在弹窗中点击【Add From…】手动添加引用,我的电脑中
    1. notion image
  1. 我的电脑中,Windows SDK 的路径是 C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0
    1. notion image
  1. 添加 Windows.winmd 后,编译问题解决,但是工程文件会被修改,需要提交,Windows 程序集的引用路径由配置项改为本机相对路径,这个改动不合理,引出方案二。
    1. notion image

方案二:重置注册表中 Windows SDK 的值【推荐】

  1. 查看 HoloLens.Automation.csprojWindows10SdkPath Windows10SdkLatestVersion 是从注册表里读取的值
    1. notion image
  1. 检查注册表,发现注册表里填写的是已经被删掉的 Windows SDK 的路径,手动修正后,编译问题解决
    1. notion image
      注册表里错误的路径是之前安装 vs2022 时安装的 Windows SDK,后来从控制面板删掉了该版本 Windows SDK,现在看来从控制面板删 Windows SDK 不会修改注册表,可能导致类似的环境问题。

参考