UWP CMake项目XamlCompiler错误WMC1002

UWP CMake项目XamlCompiler错误WMC1002,xaml,visual-c++,cmake,windows-10,uwp,Xaml,Visual C++,Cmake,Windows 10,Uwp,我正在尝试将通用Windows平台应用程序迁移到CMake,在构建时收到以下错误: \src\windows-uwp\App.xaml : XamlCompiler error WMC1002: x:Class type 'langdetect.App' is not found in 'langdetect' 在迁移过程中,我确实更改了名称空间的名称以匹配CMake项目名称,但我几乎可以肯定我已经更新了所有引用。所有的C/C++代码都编译得很好。我正在使用CMake 3.5.2和V

我正在尝试将通用Windows平台应用程序迁移到CMake,在构建时收到以下错误:

\src\windows-uwp\App.xaml : XamlCompiler error WMC1002: x:Class type 'langdetect.App' is not found in 'langdetect'     
在迁移过程中,我确实更改了名称空间的名称以匹配CMake项目名称,但我几乎可以肯定我已经更新了所有引用。所有的C/C++代码都编译得很好。我正在使用CMake 3.5.2和Visual Studio Community 2015

这是App.xaml:

<Application
x:Class="langdetect.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:langdetect"
RequestedTheme="Light">

</Application>

如果其他人有这个问题,我会发布我是如何解决的

CMake没有为我的应用程序正确生成Visual Studio项目文件。要修复原始错误,我需要更改生成的Visual Studio项目文件(.vcxproj)中的几行

我花了很长时间才弄清楚是什么原因造成的。同样,它是由生成的项目文件的另一个问题引起的

<ClInclude Include="App.xaml.h" />
<ClInclude Include="MainPage.xaml.h" />

XAML页面的ClInclude标记需要一个子DependentUpon标记才能正常工作。我把上面的代码改成了下面的代码,它解决了我的问题

<ClInclude Include="App.xaml.h">
    <DependentUpon>App.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="MainPage.xaml.h">
    <DependentUpon>MainPage.xaml</DependentUpon>
</ClInclude>

App.xaml
MainPage.xaml

我不确定这是一个bug还是我的CMakeLists.txt的问题

如果其他人有这个问题,我会发布我是如何解决的

CMake没有为我的应用程序正确生成Visual Studio项目文件。要修复原始错误,我需要更改生成的Visual Studio项目文件(.vcxproj)中的几行

我花了很长时间才弄清楚是什么原因造成的。同样,它是由生成的项目文件的另一个问题引起的

<ClInclude Include="App.xaml.h" />
<ClInclude Include="MainPage.xaml.h" />

XAML页面的ClInclude标记需要一个子DependentUpon标记才能正常工作。我把上面的代码改成了下面的代码,它解决了我的问题

<ClInclude Include="App.xaml.h">
    <DependentUpon>App.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="MainPage.xaml.h">
    <DependentUpon>MainPage.xaml</DependentUpon>
</ClInclude>

App.xaml
MainPage.xaml

我不确定这是一个bug还是我的CMakeLists.txt的问题

这可以通过两种方式解决:

  • 在Visual Studio中,在App.xaml的属性“常规”中,将
    项类型设置为
    xaml应用程序定义
  • CMakeLists.txt
    中,添加以下行:
    set\u source\u files\u properties(App.xaml properties VS\u xaml\u TYPE ApplicationDefinition)

  • 有关此CMake属性的说明,请参阅。

    这可以通过两种方式修复:

  • 在Visual Studio中,在App.xaml的属性“常规”中,将
    项类型设置为
    xaml应用程序定义
  • CMakeLists.txt
    中,添加以下行:
    set\u source\u files\u properties(App.xaml properties VS\u xaml\u TYPE ApplicationDefinition)

  • 有关此CMake属性的解释,请参阅。

    它可能是项目级别的默认命名空间。

    它可能是项目级别的默认命名空间。

    我会查看一些更详细的日志,并确保在xaml编译器访问app.xaml之前编译了app.xaml.cpp/h。我会查看一些更详细的日志并确保在xaml编译器访问app.xaml之前编译了app.xaml.cpp/h。
    Generated Files\XamlTypeInfo.g.cpp(66): error C2039: 'MainPage': is not a member of 'langdetect' [build\langdetect.vcxproj]
      include\windows-uwp\App.xaml.h(10): note: see declaration of 'langdetect'
    Generated Files\XamlTypeInfo.g.cpp(66): error C2065: 'MainPage': undeclared identifier [build\langdetect.vcxproj]
    Generated Files\XamlTypeInfo.g.cpp(82): error C2440: 'initializing': cannot convert from 'overloaded-function' to 'Platform::Object ^(__cdecl *)(void)' [build\langdetect.vcxproj]
      Generated Files\XamlTypeInfo.g.cpp(82): note: None of the functions with this name in scope match the target type
    
    <ClInclude Include="App.xaml.h" />
    <ClInclude Include="MainPage.xaml.h" />
    
    <ClInclude Include="App.xaml.h">
        <DependentUpon>App.xaml</DependentUpon>
    </ClInclude>
    <ClInclude Include="MainPage.xaml.h">
        <DependentUpon>MainPage.xaml</DependentUpon>
    </ClInclude>