Project (bin) folder path at compile time?

后端 未结 3 1276
暗喜
暗喜 2021-01-01 06:01

Is there a way to find out the project path at compile time?

I want to create a unit test that tests if the configurartion in the default web.config (the one in the

3条回答
  •  耶瑟儿~
    2021-01-01 06:11

    If you want the Visual Studio project path, at compile time, you could use a Pre-Build Event (see the Project Properties dialog) to run a command line that will create a source file used in your project.

    The source file will contain some code, say a variable definition. Your testing code uses this variable. The value of the variable will come from VS; when it runs your Pre-Build Event command, it substitutes project properties for certain macros. The macro you want is probably ProjectDir.

    So in the end, you have something like this for your Pre-Build Event's command:

    echo 'const char * PROJECT_PATH = "$(ProjectDir)";' > source.cpp
    

    Not sure what language you're using, so adjust accordingly.

提交回复
热议问题