How to access resources when running app in Visual Studio?
-
12-06-2021 - |
Question
in my application, I use various resources. I specified pre-build events to copy my resources to output directory. My directory structure looks like this:
/Debug/Models/
/Debug/Shaders/
/Debug/Textures/
/Debug/sfero.exe
/Debug/...
I want to access these resources relative to the .exe file and that works fine when I run the executable directly from Debug folder, but when I run it in Visual Studio, it is being launched in different directory, thus I cannot access my resources. Obviously, I don't want to copy my resources to location from where Visual Studio runs my application.
Any suggestions? Thanks
Solution
You can either make your application logic smarter about searching for resources, or you can pass command-line parameters (see the Debugging area of Project Properties) when launching from Visual Studio, passing the path where to look.
OTHER TIPS
The default current directory in Visual Studio is defined as $(ProjectDir)
- which is by default the location of your vcproj file.
Go to your project's Properties
-> Configuration Properties
-> Debugging
-> Working Directory
and change it to $(SolutionDir)$(Configuration)\
or whatever your Output Directory
points to.