I was setting up a Git repository and had some trouble with Visual Studio’s build files. I initially added all files to the git repository expecting anyone to be able to open my Visual Studio solution (.sln) file so my team can compile their code. That was silly of me, considering Visual Studio sets up a lot of Computer specific references and running a VS Solution file that was not made on your computer confuses Visual Studio.
So when I setup my git repository I only included the following:
Binaries/Win64/UE4Editor-Test123.dll
Config
Content
Source
Test123.uproject
This allows me to open the Test123.uproject in the Unreal Editor then select “Add Code to Project” which generates a Visual Studio Solution and the “Intermediate” directory that contains several Visual Studio build files. However when I attempt to compile this Solution it gives the following errors:
Error 1 error LNK1104: cannot open file 'C:\Users\Flip\Documents\Unreal Projects\Test123\Binaries\Win64\UE4Editor-Test123.dll' C:\Users\Flip\Documents\Unreal Projects\Test123\Intermediate\ProjectFiles\LINK Test123
Error 2 error : Failed to produce item: C:\Users\Flip\Documents\Unreal Projects\Test123\Intermediate\Build\Win64\Test123Editor\Development\UE4Editor-Test123.exp C:\Users\Flip\Documents\Unreal Projects\Test123\Intermediate\ProjectFiles\ERROR Test123
Error 3 error MSB3073: The command ""C:\Program Files\Unreal Engine\4.0\Engine\Build\BatchFiles\Build.bat" Test123Editor Win64 Development "C:\Users\Flip\Documents\Unreal Projects\Test123\Test123.uproject" -rocket" exited with code -1. C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.MakeFile.Targets 38 5 Test123
Though if I close Visual Studio/Unreal Editor and compile again it Builds fine. So my question is how can I only include my Config, Content, and Source while being able to open in Unreal Editor and compile in Visual Studio (without doing the round-about steps above)?
Did you have the Editor open when you initially attempted to compile the code in VS?
Also, while it’s not related to the error you really shouldn’t be putting UE4Editor-Test123.dll into your git repo.
I am using the gitignore file to exclude the remaining files from being added to my repository. That’s not my issue though, it is the fact I cannot create a Visual Studio .sln file with the source files.
I’m not sure if I had the Editor open, I will try again with it closed on the initial compile. Also, I only have the .dll files in the repository so my .uproject will continue to work. Should I not include the .dlls or the .uproject?
If you had the Editor open while trying to compile your project then it would explain why Visual Studio couldn’t overwrite the .dll at the end of the build process. You shouldn’t include the UE4Editor-Test123.dll in your git repo because it’s the output of the build process, it will be rebuilt from the source as necessary. The .uproject should be in your git repo. The .sln/.sdf/.suo should not as they can be regenerated from the .uproject. More details on what to include and what to exclude from your git repo can be found here.
I believe I did have the Editor open when I attempted to compile. I did the following to test:
Created a New Project in Unreal Editor
Compiled with Visual Studio
Removed files (all but the Binaries, Content, Source, and .uproject)
Opened the Unreal Editor on the .uproject
Selected “Add Code to Project” (Added a random class because this recreates/adds a Visual Studio Solution to the Project)
Selected Yes to edit the code
Once Visual Studio opened, closed the Unreal Editor
Compiled the project in Visual Studio and it built successfully
This means I can store the files from my original post in my git directory and have my team run through steps 4-8 whenever they clone the repo. This can’t be the best way to setup a Visual Studio solution for UE4 but, it’s the best way I’ve found this far.