So, the idea is the following: when a Rebuild is happening we create an anchor. And another thing - it seems vcxproj is broken at some poin - I was not able to integrate the way I wanted with only BeforeRebuild and AfterRebuild targets - I had to redefine hole Rebuild target (it is located in C:\Windows\Microsoft.NET\Framework\v9\)
Obviously, you could do the same or you could use different batch files.įirst of all - do not take my code 'as is' - it is terrible one with lots of hacks, I had no idea msbuild is so broken by default (it seems at work I have access to waaaay more commands that make life easier). In my testing above I use a single build batch file for both the build and rebuild. There probably is a VS macro to handle this, but I am not sure since it has been ages since I've done anything with C/ C++. Your projects will have to account for the release version. My screen shots above only show the debug version of the properties.
When the console application is rebuilt (during a rebuild), it will also rebuild the NMake project. When the console application is built (during a build), it will build the NMake project if needed, and use the output (lua.lib) during the linker stage. I also added the lua.lib file as an input during the application's link stage: Here is the console application's reference page: In my console application, I added a reference to the NMake project - this way the NMake project is built prior to the console application. If you do a rebuild, then a new lua.lib file is created. Now if you do a build, the lua.lib file will only be created if it is not there. I am not really sure what the Output command is used for, but I just filled in the path to the build output (lua.lib). My Clean command just deletes the output. My Rebuild command always calls the batch file. If it does not exist, then it calls the rebuild.bat batch file. My Build command just checks for the existence of the output file (lua.lib).
I don't have a screen shot of the above dialog with my commands, but here is my NMake project's properties: In Visual Studio, if you create a new NMake project, you will see a dialog that allows you to provide MS-DOS commands:Īs you can see, there are commands for: Build, Clean, Rebuild, and others. I believe this is just a naming difference, and that the underlying build project remains the same between the two versions.Īs a simple test, I created two Visual Studio applications: 1) an NMake project that calls a batch file to create a static library, and 2) a console application that consumes the library from step 1. For discussion purposes here, I will refer to the project type as "NMake". Note that later versions of Visual Studio simply refer to the project type as "Make". If you create an NMake project, you will be able to know which type of build ( build or rebuild) is occurring. My approach is to remove the build of the Lua library from the pre-link step to a separate Visual Studio NMake project. I will, however, suggest an alternate approach.
I do not know if the exact thing that you are asking can be done - perhaps someone else knows how to do it.
cmd script run from within a Visual Studio (2005, 2008, 2010, 20 respectively) project's pre-link stage determine whether this is a full rebuild.