0

Working on a very large C# project with multiple subportions. One of these portions creates and places dlls in a specific location for consumption. As per a recent change we're now trying to place these dlls with every root build call made. (Use to be manually placed every milestone or so)

So I'm referencing the dirs.proj file that is compiling the subdirectory which creates and places the dlls. That all works fine. The problem is that for one reason or another other portions of the project start to look for these dlls before that part has finished compiling.

How can I ensure that this part of the project gets compiled and places the dlls before beginning to compile the rest of it? I have a very brief understanding of and but really don't know how to use them to do what I want.

Thanks for any and all help!

  • You can change the build order of projects ([see this question](http://stackoverflow.com/questions/3653973/visual-studio-2010-how-to-enforce-build-order-of-projects-in-a-solution)). Also make sure all projects are marked as `Build` in `Configuration Manager`. Finally, to prevent parallel builds, goto `Tools->Options->Projects and Solutions->Build and Run` and change `maximum number of parallel project builds` to 1 (this usually isn't a problem though, as the compiler should be able to figure out dependencies). – Arian Motamedi Aug 11 '14 at 22:10

2 Answers2

0

Read up on Build Targets and the MakeDir task.

You'll want to include the logic creating the new directory in a task that is scheduled to occur prior to the default Build task.

<Target BeforeTargets="Build" Name="CreateRequiredFolder" Condition="!EXIST('$(MyDirectory)')" >
    <MakeDir Directories="$(MyDirectory)" />
</Target>

Note how we use BeforeTargets to schedule this before Build, and the condition on the target causes it to be skipped if the desired folder already exists.

Nicodemeus
  • 4,005
  • 20
  • 23
  • I'm not interested in creating a directory though, it already exists. The problem is ensuring building the appropriate .proj file occurs before the others try to execute. How can I make a target tag build a certain proj? – user559399 Aug 11 '14 at 23:01
  • The tag you want is called "ProjectReference" and it will place a dependency to build that project before he current project is built. – Nicodemeus Aug 12 '14 at 20:21
0

Here is what I ended up doing to get it to work.

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="......." InitialTargets="BuildWebshared">


<ItemGroup>
  <WebsharedProjects Include="..\location\dirs.proj" />
</ItemGroup>

<Target Name="BuildWebshared">
  <MSBuild
    Projects="@(WebsharedProjects)"
    Targets="Build">
  </MSBuild>
</Target>
....