1

我有一个包含两个项目的 Visual Studio 2019 解决方案。

第一个项目是使用“Windows 运行时组件 (WinUI 3) Visual Studio 模板(库项目)创建的。它生成一个 dll 和关联的 winmd 文件,其中包含一个基于 DirectX 的 Windows 运行时组件,用于WinUI 3.0 应用程序。

第二个项目是使用“Blank App, Packaged (WinUI 3 in Desktop)”Visual Studio 模板创建的。它生成一个使用 WinUI 3.0 作为 UI 框架的 Win32 应用程序,并使用第一个项目的输出。

第二个项目通过 Visual Studio / MSBuild 项目引用引用了第一个项目。

第一个项目通过MIDL如下方式定义组件:

namespace My.Company.Name.DirectX
{
  runtimeclass CustomControl : Microsoft.UI.Xaml.Controls.SwapChainPanel
  {
    CustomControl();
    // All interface methods and properties
  }
}

从 this 中生成的标头如下所示:

namespace winrt::My::Company::Name::DirectX::implementation
{
  struct CustomControl : CustomControlT<CustomControl>
  {
  public:
    CustomControl();
    ~CustomControl();
    // // All interface methods and properties
  };
}

namespace winrt::My::Company::Name::DirectX::factory_implementation
{
  struct CustomControl : CustomControlT<CustomControl, implementation::CustomControl>
  {
  };
}

然后,我尝试在Microsoft.UI.Xaml.Controls.PageXAML 文件中使用该组件,如下所示:

<Page
  x:Class="My.Company.Name.App.CustomControlPage"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="using:My.Company.Name.App"
  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  xmlns:Controls="using:My.Company.Name.DirectX"
  mc:Ignorable="d">

  <Controls:CustomControl/>

</Page>

但是,如果我编译整个代码,我会收到以下错误消息:

My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(145): message : see reference to class template instantiation 'winrt::My::Company::Name::App::implementation::CustomControlPageT<D,I...>' being compiled (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,66): error C3646: 'CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(29,76): error C2059: syntax error: '(' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(30,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,62): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,71): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(33,1): error C2061: syntax error: identifier 'CustomControl' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,46): error C3083: 'DirectX': the symbol to the left of a '::' must be a type (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,55): error C2039: 'CustomControl': is not a member of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(10): message : see declaration of 'winrt::My::Company::Name' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,66): error C3646: '_CustomControl': unknown override specifier (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,77): error C2059: syntax error: '{' (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(134,1): error C2334: unexpected token(s) preceding '{'; skipping apparent function body (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,13): error C3861: '_CustomControl': identifier not found (compiling source file Page\CustomControlPage.cpp)
My.Company.Name.App\Generated Files\Page\CustomControlPage.xaml.g.h(35,27): error C3861: 'value': identifier not found (compiling source file Page\CustomControlPage.cpp)

CustomControl不知何故,在编译为引用它的 XAML 文件生成的源代码时,无法识别my 。我不明白问题是什么。理论上,使用该组件所需的只是 winmd 文件,因为它应该描述该组件。

有人可以告诉我为什么会出现这些错误吗?

编辑:

我试图重现该问题,生成的 Git 存储库可在此处获得

4

0 回答 0