Интеграция с Cortana: невозможно установить XML-файл VCD

Я следую документации от 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. Однако я получаю следующее сообщение об ошибке...

"Система не может найти указанный файл"

Вот мой код для метода 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>

Что я делаю не так?


person ProSamHDx    schedule 28.12.2016    source источник


Ответы (1)


Я проверил ваш код на своей стороне, и в вашем коде все в порядке. Судя по ошибке

"Система не может найти указанный файл"

Наиболее возможная причина — что-то не так с расположением файла или именем файла. Во-первых, убедитесь, что имя файла совпадает с определенным кодом. После того, как вы создали новый файл xml для файла VCD, имя, которое вы определили, должно быть VoiceCommandDefinitions, а не VoiceCommandDefinitions.xml, файл уже имеет суффикс при его создании.

Во-вторых, убедитесь, что ваш файл VCD действительно находится в корне вашего проекта, как показано на следующем рисунке.

введите здесь описание изображения

Наконец, также убедитесь, что свойство Build Action файла содержится в проекте, что гарантирует, что файл может быть найден при запуске проекта (щелкните правой кнопкой мыши файл -> свойства).

введите здесь описание изображения

person Sunteen Wu    schedule 29.12.2016
comment
Привет @Sunteen! Спасибо за ваш ответ. К сожалению, следуя вашим инструкциям, я все еще сталкиваюсь с той же ошибкой. Посмотрите скриншот здесь: imgur.com/a/gEx27 Что я упустил? - person ProSamHDx; 29.12.2016
comment
@SamDHarris, не могли бы вы поставить точку разрыва в этой строке кода и сделать снимок экрана, чтобы я мог видеть, что эта строка вызывает исключение. - person Sunteen Wu; 30.12.2016
comment
Еще раз спасибо, @Sunteen, я не совсем понимаю, о чем вы спрашиваете, поэтому вот: imgur.com/a/sOcap — это снимок экрана с информацией, содержащейся в переменной vcdStorageFile. Надеюсь, это поможет :) - person ProSamHDx; 31.12.2016