4
votes

I have a VS 2005/MSBuild 2.0 project (let's call it "Project A") that I must keep in VS 2005 (it uses a third-party VS 2005 Designer.) Project A is referenced by one of the projects in my new VS 2008 solution (we'll call them "Project C" and "Solution B" respectively.) Ideally, I'd like to chain the building of Project A into the building of Solution B, and I believe that the "ToolsVersion" attribute is the key. So, to recap, this is what I need to do:

  1. Start a build on Solution B either through the command-line or Visual C# 2008 Express. It is critical that it work through both!
  2. Have Project C trigger the building of Project A.
  3. Have the output of Project A (a class library) copied to Project C.
  4. Build Project C and the remaining projects in Solution B.

Here's a diagram:
MSBuild 3.5 or VS2008->
[Solution B (3.5)]->
[Project C (3.5)]->
[Project A (2.0)]->
Copy output of A to C->
Continue building Solution B

Any ideas on how I should set this up? Clips from working project files would be hugely appreciated! Thanks in advance!

SOLUTION
Here's what needed added to Project C, to make this work:

<ItemGroup>
   <ProjectToBuild Include="..\ProjectA\ProjectA.csproj" />
</ItemGroup>
<Target Name="BeforeBuild">
   <MSBuild
     Projects="@(ProjectToBuild)"
     Targets="Rebuild" ToolsVersion="2.0">
              <Output
              TaskParameter="TargetOutputs"
              ItemName="AssembliesBuiltByChildProjects" />
   </MSBuild>
   <Copy SourceFiles="@(AssembliesBuiltByChildProjects)"
            DestinationFolder="$(MSBuildProjectDirectory)"
    />
</Target>

Note there is a known issue with getting the TargetOutputs of a solution with the MSBuild task. This was supposed to be fixed in MSBuild 3.5, but I'm guessing that the ToolsVersion attribute is causing it to resurface. That's why I'm referencing ProjectA.csproj directly, instead of its solution file.

4
Why must project A be built with solution B at all? Can't you just reference the project A assembly along with other dependencies from solution B?kay.herzam
Of course. But if I can get this set up (and I'm pretty sure it's possible), I can have my build server and my developers know immediately if a change in Project A broke Project C.GuyBehindtheGuy

4 Answers

2
votes
  1. Ensure that the project C is a dependency of project B. (In this case there isn't a project B but if there was then make sure.)
  2. Edit project C's proj file in a text editor. Add the followingat the bottom of the file but before the closing project tag, where a.sln is the solution for project A.

    <ItemGroup>
       <ProjectsToBuild Include="a.sln"/>
    </ItemGroup>
    <Target Name="BeforeBuild">
       <MSBuild
             Projects="@(ProjectsToBuild)"
             Targets="Build" ToolsVersion="2.0">
                      <Output
                      TaskParameter="TargetOutputs"
                      ItemName="AssembliesBuiltByChildProjects" />
        </MSBuild>
        <Copy SourceFiles="@(TargetOutputs)"
                    DestinationFolder="@(SolutionDir)\References"
          />
      </Target>

  3. Create a references folder under you solution and ensure that it is marked as a reference folder for project C.

  4. Build Project B.

I haven't tested it but the concept should work.

1
votes

You have not told the specific reason why you need to use Visual studio 2005 on that one project. (I know there are valid reasons to do so, but they might imply different solutions.)

What I once did successfully was to set binary, include and library paths in VS2008 to use the Compiler and includes of vs2005 (it was a win32 c++ project).

You can remove /nologo from the compiler options to actually see the compiler version used.

HOWTO:

  • Copy and rename the 2005 project before converting it to 2008. (to have a clean 2005 version of it available)
  • Add the new converted project to the 2008 Solution, set dependencies.

  • Add a properties-page-thingy (don't know what it is called in English, it's a .vsprops file) to the 2008 Version of the project with the binary, assembly and include directories set to that of your 2005 installation, thus forcing vs2008 to use the 2005 toolset for that project. You might need the professional version of vs2008 to create such a file, but all versions should be able to read it)

Basically, you will use only the editor component of 2008, and the compiler of 2005, for that project.

There might be better solutions to this, but since you have no answers so far, I propose this workaround.

1
votes

How about this: Edit project C's proj file to include an Exec MSbuild task that calls VS2005 devenv with /build switch to build project A and then copy the output files from project A build to a location where project C could find. You need to do in a build step in project C's proj file before project C is compiled, BeforeBuild maybe, so that project C can find the output of project A.

1
votes

Just SLN format is different in VS2008, the CSPROJ/VBPROJ files "can" remain same... So basically you will need two SLN files adding your CSPROJs/VBPROJs in both SLNs.

Read http://weblogs.asp.net/palermo4/archive/2007/07/30/managing-projects-in-visual-studio-2005-amp-2008.aspx for more info.