I'm using VC++ and want to write a script that can scan my source-code and at some开发者_如何学C places where it sees a text like "abc" then extract characters of that text and generate a selective piece of code like ones below at build time:
first example of a piece of code :Func1(a);
Func2(b);
Func3(c);
second example of a piece of code:
{'a','b','c'}
I want to incorporate the script into build process as somebody has told me it is possible but don't know how, please tell how.
In the project properties of Visual Studio, you will have the option "Pre-Build Event" and "Post-Build Event".
At these configurations you can input programs that should be executed before and after your build. You can use project variables to identify your solution folder, project folder, binary, etc. If you are using a recent version of Visual Studio, there is a button below the text box that give you access to those variables.
Make sure that whatever you call at this configuration would be executed from the shell environment (cmd
), otherwise you will receive a build error. Scripts will probably required that you input a call to the interpreter and pass the file as a parameter.
For example, let's say I need to run a Python script before I build my code. I would configure the Pre-Build Event as:
c:\python\python myscript.py
One good advice is to use DOS Batch files (.bat) to wrap around whatever you need to run and add those to your build events. There are plenty of tutorials over the net on how to create bat files, and they are fairly simple.
精彩评论