Visual Studio: how to only run Custom Build Step when 'necessary'
Asked Answered
M

2

6

I am using a Custom Build Step to copy the built DLL (i.e. $(TargetPath)) of a C++ project to a different location on disk.

I've set the Output of the Custom Build Step to the destination DLL path, and Additional Dependencies to $(TargetPath) - the file I'm copying, in the hope that VS will then only run the step if the source DLL is newer than the target DLL.

However, each time I build the project, VS runs the custom build step - so it appears to be unable to tell that there's no need to perform the copy, (the source DLL $(TargetPath) hasn't changed). I must have the step configured incorrectly.

What settings will give me the behaviour that I want (i.e. - VS regards the project as up-to-date if it built and the custom build step was successful)?

In the VS Output Window I see this line which seems to imply that visual studio is taking the vcxproj as the file that triggers the build step. I want it to use $(TargetPath):

Input file "MyProject.vcxproj" is newer than output file "c:\custom\build\step\copies\the\dll\here.dll".

(PS: I should add, I was initially using a Post Build Step, but if this fails, VS regards the project as successfully built, and doesnt run it again when you Build a second time)

Middleoftheroader answered 18/10, 2013 at 16:59 Comment(0)
M
0

I think what you want is Incremental Building.

Here is a quick howto on it: http://msdn.microsoft.com/en-us/library/ms171483.aspx

The basics are you need to supply an input to the target to so MSBuild can map the inputs to outputs and skip the target if the output is newer/same age as the input.

Mongol answered 18/10, 2013 at 17:19 Comment(1)
I don't think so. I'm in a Visual Studio project, so the build target is already defined as the DLL that gets built.Middleoftheroader
S
0

Make sure the timestamp of the output file you specified is updated after the copy command (in Unix you would use the touch command).

You may use this at the Command Line:

cd c:\custom\build\step\copies\the\dll <br>
copy /b /y YOUR_SOURCE_DIRECTORY/here.dll .<br>
copy /b /y here.dll+,,
Spiry answered 20/3, 2015 at 13:13 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.