0

I am working on a project in VS 2019 and am trying to use the latest winrt/c++ machine learning api. Therefore I conducted the following steps:

  1. Install Microsoft.AI.MachineLearning 1.4.0 NuGet package for specific project
  2. Build the project
  3. Add #include "winrt/Microsoft.AI.MachineLearning.h" Unfortunately, the header source file is not found. What am I doing wrong?
Camill Trüeb
  • 348
  • 1
  • 2
  • 16
  • Technically, that should be `#include `, not `#include "winrt/Windows.AI.MachineLearning.h"`. Although it would certainly help to see the complete, unabridged error message. – IInspectable Aug 12 '20 at 14:33
  • Thank you for your answer. I assumed, using `"`for includes makes more sense, since the NuGet package is installed to the current solution. Anyways, it certainly does not solve the problem. Also it is not `Windows.AI.MachineLearning.h` but `Microsoft.AI.MachineLearning.h`, since I am using the NuGet package. The exact error is: `E1696 cannot open source file "winrt/Microsoft.AI.MachineLearning.h"` – Camill Trüeb Aug 12 '20 at 15:46
  • `E1696` is not a compiler error. – IInspectable Aug 12 '20 at 16:08
  • @JamesTrüeb, please use `#include"abi/Microsoft.AI.MachineLearning.h"`. – Mr Qian Aug 13 '20 at 02:17
  • @JamesTrüeb,any update about this issue? – Mr Qian Aug 13 '20 at 09:59

1 Answers1

1

Cannot open microsoft.ai.machinelearning.h from NuGet package

When you install the nuget package Microsoft.AI.MachineLearning 1.4.0, you should use this

#include "abi/Microsoft.AI.MachineLearning.h"

Actually, Microsoft.AI.MachineLearning.h file exists under the abi folder from your nuget package.

================

Update 1

I have reproduced your issue in my side. And it seems that there is no such error in my side. I just create such project followed by the above document, then install that nuget package-->build the project and after that, I can call `winrt/Microsoft.AI.MachineLearning.h.

And the winrt c++ project just puts such file into Generated Files folder during build process based on the function of the project.

So it is a quite strange behavior, and I suggest you could follow these steps to troubleshoot it:

Before all, you could check this document first.

1) First, close your Windows Console Application (C++/WinRT) project, delete .vs hidden folder, any output folders like Debug or Release under the solution folder and project folder.

2) Then restart your project and make sure that Microsoft.AI.MachineLearning 1.4.0 NuGet package is installed.

Then rebuild your project and make sure that build process is successful.

3) Then I can call #include "winrt/Microsoft.AI.MachineLearning.h".

enter image description here

If these steps do not help, I think VS or your current project itself has something wrong.

please try to disable any other third party extensions under Extensions-->Manage Extensions and then restart VS to test it.

Or just create a new WinRT C++ project to test whether the issue happens in the new project.

Mr Qian
  • 21,064
  • 1
  • 31
  • 41
  • Thank you, this works. I have tried this header before, but did not realise it was in the `ABI` namespace. Do you know why I have to include this header, as this is against the documentation? I have used the same Nuget Package in another VS 2019 solution and there were no issues importing the Microsoft.AI.MachineLearning package, but with this existing application it does not work. – Camill Trüeb Aug 13 '20 at 13:54
  • Also, I realised this header does not provide the same abstraction level unfortunately, as in the winrt/Microsoft.AI.MachineLearning API. – Camill Trüeb Aug 13 '20 at 14:23
  • Given that these two same projects do the same steps but get different behaviors, I suspect that your first project itself made some changes. So please enter the first successful project, please right-click on the project `properties`-->`C/C++`-->`Additional Include Directories` and check whether these paths have a folder called `winrt`. – Mr Qian Aug 14 '20 at 03:10
  • The `#include " "` is controlled by the `Additional Include Directories` and if my guess is right which there is folder called `winrt` and it contains the files you want, the behavior is controlled by someone rather than the nuget package. To get this in the second project, you should copy the same path in the `Additional Include Directories` to let your second project identify the `WinRT` folder. As for the origin of the folder, you need to consult the person who made the change. – Mr Qian Aug 14 '20 at 03:15
  • Please let us know if it does help. – Mr Qian Aug 14 '20 at 03:15
  • I think this is untrue. I think VS should create a folder called `generated files', including the relevant headers from the NuGet package, in the winrt namespace. This is according to the Microsoft Machine Learning documentation. Even though I am not sure if this behaviour is dependent on the c++/winrt VSIX extension. Since this folder gets created in the Solution directories, VS locates it without using Additional Include Directories. – Camill Trüeb Aug 14 '20 at 07:12
  • Sure. You are right.I have reproduced your issue in my side and I can get `#include "winrt/Microsoft.AI.MachineLearning.h"`. – Mr Qian Aug 14 '20 at 08:12
  • Or did you change your configuration or platform to any others without a new build process? The included files are generated by the build process with the related `configuration` and `platform`. When you use it, you must build it with the corresponding platform or configuration first, so that you can find the header file. – Mr Qian Aug 14 '20 at 08:38
  • @JamesTrüeb Did you have any progress about this issue? – Mr Qian Aug 18 '20 at 09:37
  • thank you for your answer update and sorry for my late answer; I have tried it out and what actually worked was deleting the .vs folder on solution level and rebuilding the whole solution. So I guess I have messed up something with my property sheets or my build sequence was wrong, but a complete reset solved the issues. Somehow I assumed the NuGet Package manager should load all dependcies autonomously. – Camill Trüeb Aug 20 '20 at 11:46