How to access the $(SolutionDir) macro from C++ code. Simply I want to get the solution directory path as a string. So that I can setup my project in any computer and get the sln directory path accordingly.
I have the same issue some time ago (I will note down vote but there is no really answer here).
What I did was also define Preprocesor macro and with c++11 one can easily escape the problem of escapes characters. To do that go into
Properties → Configuration Properties → C/C++ → Preprocessor
There is field PreprocessorDefinitions so you need to add there:
SOLUTION_DIR=R"($(SolutionDir))"
To explain the R"()" stands for c++ string literal so there will be no problem with escape characters (they are available since C++11).
From my use case this works perfectly in Visual Studio 2015 and 2017 (should also work in 2013 and 2012. In 2010 and before there was no support for Raw String)
I solved this. Here using the $(SolutionDir) is giving the solution directory path. But there is a problem when it takes as a string because of return statement of $(SolutionDir) contains the path including slashes () without escape character. Ex: C:\TestApp\ But to use as string it should be C:\TestApp\ Perhaps it can be used internally when setting the properties.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With