How to build projects that aren't in the Visual Studio Solution?

150 views Asked by At

Is there a way to tell Visual Studio to build projects that aren't part of its solution? We've been looking into many different options without success such as nested projects, shared projects, and build events.

Example architecture:

Project A
Project B
    ref Project i
    ref Project ii
Project C
--------------
Solution 1
    Project A
    Project B
    Project C
Solution 2
    Project i
    Project ii

Right now, I can't build Solution 1, because Project B won't build, because Projects i and ii haven't been built. I have to switch to Solution 2, build that, and return to Solution 1 and then the build works. This doesn't sound like the best way to do things, but I'm not the one to decide and am looking for a way to ease the process without adding Projects i and ii to the solution itself, even though adding some build events or whatnot to the solution would be permitted. How can I achieve this?

1

There are 1 answers

0
DMX David Cardinal On BEST ANSWER

The solution we've come up with was to add a pre-build target in the C# projects that have project dependencies outside the solution. Namely, Project B now contains something like this:

<ItemGroup>
    <ProjectDependency Include="..\Solution2\Project-i.csproj"/>
    <ProjectDependency Include="..\Solution2\Project-ii.csproj"/>
</ItemGroup>
<PropertyGroup>
    <BuildDependsOn>
        BuildProjectBDependencies;
        $(BuildDependsOn)
    </BuildDependsOn>
</PropertyGroup>
<Target Name="BuildProjectBDependencies">
    <MSBuild Projects="@(ProjectDependency)"
             Properties="OutDir=$(OutputPath);
                         Configuration=$(Configuration)"
             Targets="Build" />
</Target>

Attempting to build Project B first requires Project i and Project ii to be built, whether this is in Visual Studio or using an automated build process.