【问题标题】:Cortana Integration: Unable to install VCD XML fileCortana 集成:无法安装 VCD XML 文件
【发布时间】:2016-12-28 20:26:34
【问题描述】:

我正在关注此处的 Microsoft 文档:

https://msdn.microsoft.com/en-us/cortana/voicecommands/launch-a-foreground-app-with-voice-commands-in-cortana#Install_the_VCD_commands

将 Cortana 集成到我的 Windows 10 应用程序中。但是,我收到以下错误消息...

“系统找不到指定的文件”

这是我尝试安装 VCD 的 OnLaunched 方法的代码...

protected  override async void OnLaunched(LaunchActivatedEventArgs e)
{


    Frame rootFrame = Window.Current.Content as Frame;

    // Do not repeat app initialization when the Window already has content,
    // just ensure that the window is active
    if (rootFrame == null)
    {
        // Create a Frame to act as the navigation context and navigate to the first page
        rootFrame = new Frame();

        rootFrame.NavigationFailed += OnNavigationFailed;

        if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
        {
            //TODO: Load state from previously suspended application
        }

        // Place the frame in the current Window
        Window.Current.Content = rootFrame;
    }

    if (e.PrelaunchActivated == false)
    {
        if (rootFrame.Content == null)
        {
            // When the navigation stack isn't restored navigate to the first page,
            // configuring the new page by passing required information as a navigation
            // parameter
            rootFrame.Navigate(typeof(MainPage), e.Arguments);
        }
        // Ensure the current window is active
        Window.Current.Activate();
    }

    try
    {
        //StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync("VoiceCommandDefinitions.xml");
        //await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(vcdStorageFile);

        var storageFile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///VoiceCommandDefinitions.xml"));
        await VoiceCommandDefinitionManager.InstallCommandDefinitionsFromStorageFileAsync(storageFile);

    }
    catch (Exception)
    {
        throw;
    }
}

我在项目的根目录中获得了 VCD 文件,并已将其设置为按照上面链接文档的说明复制文件。

另外,这是我的名为“VoiceCommandDefinitions.xml”的 VCD 文件。

<?xml version="1.0" encoding="utf-8" ?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
  <CommandSet xml:lang="en-gb" Name="VoiceCommands_en-gb">
    <AppName>Hero Explorer</AppName>
    <Example>Refresh the characters list</Example>

    <Command Name="RefreshCharactersLIst">
      <Example>Refresh the characters list</Example>
      <ListenFor>Refresh [the] [characters] list</ListenFor>
      <Feedback>Refreshing the characters list</Feedback>
      <Navigate/>
    </Command>

  </CommandSet>
</VoiceCommands>

我做错了什么?

【问题讨论】:

    标签: c# windows-10-universal cortana


    【解决方案1】:

    我已经测试了您的代码,您的代码没有任何问题。根据错误

    “系统找不到指定的文件”

    最可能的原因是您的文件位置或文件名有问题。首先请确保文件名与定义的代码相同。为 VCD 文件创建新的 xml 文件后,您定义的名称应为 VoiceCommandDefinitions,而不是 VoiceCommandDefinitions.xml,该文件在创建时已具有后缀。

    其次,请确保您的 VCD 文件实际上位于项目的根目录中,如下图所示。

    最后还要确保文件的Build Action属性是项目中的内容,保证项目运行时可以找到文件(右键文件->属性)。

    【讨论】:

    • 嗨@Sunteen!感谢您的答复。不幸的是,按照您的指示,我仍然面临同样的错误。请在此处查看屏幕截图:imgur.com/a/gEx27我错过了什么?
    • @SamDHarris 能否请您在该代码行上放一个断点并提供屏幕截图让我看到该行引发了异常。
    • 再次感谢@Sunteen,我不确定你在问什么:imgur.com/a/sOcap 是 vcdStorageFile 变量中保存的信息的屏幕截图。希望这有帮助:)
    猜你喜欢
    • 2016-10-15
    • 2017-05-08
    • 2016-07-22
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    相关资源
    最近更新 更多