Cortana集成:无法安装VCD XML文件

时间:2016-12-28 20:26:34

标签: c# windows-10-universal cortana

我正在关注Microsoft发现的文档:

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

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

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

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

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文件,并按照上面链接的文档的说明将其设置为复制文件。

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

<?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>

我做错了什么?

1 个答案:

答案 0 :(得分:1)

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

  

&#34;系统找不到指定的文件&#34;

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

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

enter image description here

最后,请确保文件的Build Action属性在项目中是内容的,这将保证在项目运行时可以找到该文件(右键单击文件 - &gt;属性)。

enter image description here