简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM