How to access resources when running app in Visual Studio?

666 views Asked by At

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

2

There are 2 answers

0
Ben Voigt On BEST ANSWER

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.

0
Alexandru C. On

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.