code reuse for file existence test in a Visual Studio vcxproj file
<p>I have a vcxproj file that contains explicit Windows shell commands in the NMakeBuildCommandLine section:</p>

<pre><code>&lt;NMakeBuildCommandLine Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"&gt;
move file1 file2
&lt;/NMakeBuildCommandLine&gt;
</code></pre>

<p>I'm using MSBuild to execute the vcxproj, either directly or via a sln file. The problem is that when <code>file1</code> does not exist, the output is very unhelpful and doesn't even list the file's name:</p>

<pre><code>The system cannot find the file specified.
</code></pre>

<p>My naive solution is to replace <code>move file1 file2</code> with:</p>

<pre><code>if exist file1 (move file1 file2) else (echo file1 does not exist &amp;amp;&amp;amp; exit 1)
</code></pre>

<p>(Note that I need to write <code>&amp;amp;&amp;amp;</code> instead of <code>&amp;&amp;</code>.)</p>

<p>This works, but it's error-prone because I need to type <code>file1</code> three times per line and make sure they all match. <code>file1</code> is only one of many files that need to be moved. Furthermore, the series of commands is virtually identical across the various build configurations.  </p>

<p>How can I avoid repeating myself both within a command line and across build configurations? I thought that the <code>UserMacros</code> property group might help me, but I couldn't figure out how to write such a macro via the IDE. (Right-clicking on the project in Visual Studio doesn't show a field for entering user macros.) Nor could I find any discussion of the syntax of this section on the Internet, so I didn't know how to write macros with a text editor (which I would actually prefer).</p>

<p>There may be yet a better way within a vcxproj file to identify files that need to exist, so I'm open to any alternatives.</p>