<p>I have use IlMerge to merge all the dlls of my projects in one exe. I use a targets file which is referenced in the "import" of the main csproj.</p>

<p>The ExecCommand in the targets is:</p>

<pre><code>  &lt;Exec Command="&amp;quot;$(ProgramFiles)\Microsoft\Ilmerge\Ilmerge.exe&amp;quot; /out:@(MainAssembly) &amp;quot;@(IntermediateAssembly)&amp;quot; @(IlmergeAssemblies-&gt;'&amp;quot;%(FullPath)&amp;quot;', ' ')" /&gt; 
</code></pre>

<p>This works. </p>

<p>But then I have a Setup Project, when it builds, it ignores the "import" and it doesn't merge the dlls. How can I use the targets file with the Setup Project?</p>

<p>I have tried writing this same code for Ilmerge in the Post-build event (in properties of the project) of the main project but it gives me error code 1.</p>

I'd recommend that you check out the ILMerge Task in the
MSBuild Community Tasks
. Documentation for the ILMerge Task is included in the
download
. It will take away the complexity of specifying the exact command line arguments as you are doing now.
On your specific issue, other than the error code 1, are you getting any other error message as a result?  Comment, and I'll edit my response as best I can.