Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio Post-build event: for %f in (set) command

This command in the Visual Studio 2010 Post-build event

for %f in ("$(ProjectDir)$(OutDir)*.dll") do echo %f

(echo will be replaced with some other tool) gives me the error

The command "[...]" exited with code 255.

I guess I have to escape the outermost round brackets but I don't know how. I tried \( and ((.

like image 640
herzmeister Avatar asked May 13 '11 12:05

herzmeister


People also ask

What are pre and post build events in Visual Studio?

Pre/Post Build Events Command Line In Visual Studio. Pre/Post build events are useful when we wish to perform some operation before/after a project is built. These operations are nothing but the Shell commands being used from the command line. A build event can be formed using a single, multiple, or conditional commands.

How do I create a build event in Visual Studio Code?

To specify a build event In Solution Explorer, select the project for which you want to specify the build event. On the Project menu, click Properties. Select the Build Events tab. In the Pre-build event command line box, specify the syntax of the build event. In the Post-build event command line box, specify the syntax of the build event.

How do I run a post-build event from the command line?

In the Post-build event command line box, specify the syntax of the build event. Add a call statement before all post-build commands that run .bat files. For example, call C:\MyFile.bat or call C:\MyFile.bat call C:\MyFile2.bat. In the Run the post-build event box, specify under what conditions to run the post-build event.

How to execute multiple commands in a build event?

When the build event is triggered, we can see the actual command executed by Visual Studio in the background, in its output window. We can execute multiple commands in our build event. All we need, is to add a new line between the two commands. Not only this, we can also execute commands based on some condition.


1 Answers

You might need to use %%f instead of %f for the first one (and maybe the second one). In a batch file (which VS might use to implement these custom build steps), you have to use the extra % for identifiers.

Edit: here's the first part of the output from help for on the command line.

Runs a specified command for each file in a set of files.

FOR %variable IN (set) DO command [command-parameters]

%variable Specifies a single letter replaceable parameter. (set) Specifies a set of one or more files. Wildcards may be used. command Specifies the command to carry out for each file. command-parameters Specifies parameters or switches for the specified command.

To use the FOR command in a batch program, specify %%variable instead of %variable. Variable names are case sensitive, so %i is different from %I.

like image 128
David Pope Avatar answered Oct 20 '22 01:10

David Pope