Can't add source file to C++ project

I have a small C++ project. I added a simple source file to it, just some utility code, nothing specifically game-related, call it foo.cxx and foo.h. I put the source files in Unreal Projects/MyProject/Source/MyProject with the regular source files, and regenerated the Visual Studio project (right-click on uproject in Windows file explorer, Generate Visual Studio project files). Now foo.cxx and foo.h show up in Visual Studio just fine. But the Unreal build process never tries to build my foo.cxx, so I get unresolved external symbol Foo when it links. Why doesn’t it know about my foo.cxx even though it properly generated it into the VS project?
I even tried building manually on the command line with UnrealBuildTool .... -verbose and I can see there that it doesn’t mention foo.cxx at all.

OK, I even spent some quality time with SysInternals Procmon and I can see UnrealBuildTool doing lots of stuff, but it never even queries or opens my foo.cxx. Do I have to add it to some build config somewhere?

It’s odd. I did same thing as you and launched the GenerateProjectFiles on the project. After that, the editor is able to see, compile and execute my new source files. Are you sure the added files are correct? I had some problems when the code was incorrect (but UE4 showed cryptic messages).

what is cxx? UBT only search for cpp

VS IDE project is not used in compilation process whatsoever you can compile even without it, it won’t even use VS project configuration as UBT build script are one configuring the process. UBT will add all files to VS project, but file being there means nothing.