Wednesday, March 23, 2011

How do I set the Output directory for a C++ project built by msbuild?

I have a MSBuild .proj file that is compiling a mixture of C# and C++ projects.

The C# projects compile output (.exe/.dlls) to the OutputPath I specify, but when I specify OutputPath for the C++ projects (which calls vcbuild.exe), the OutputPath is ignored and instead goes into the directory specified in the Property Pages for the .vcproj.

Here's my MSBuild task:

    <MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
             Targets="$(BuildTargets)"
             Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
    </MSBuild>

How can I specify that the C++ output files should go to the same directory as the C# output files $(ToolsOutputDir)?

From stackoverflow
  • I was able to make this work by doing the following:

    1) Installing the Microsoft SDC MSBuild Tasks Library

    2) In the property pages for the C++ projects, setting the output directory to $(OutputPath).

    3) Adding a SDC task to set the environment variable OutputPath before building the C++ projects via VCBuild:

        <Microsoft.Sdc.Tasks.SetEnvironmentVariable Variable="OutputPath" Value="$(ToolsOutputDir)" Target="Process"/>
    
        <!-- Build any CPP code x86 -->
        <MSBuild Projects="$(SourceFolder)\$(NativeSolutionName)"
                 Targets="$(BuildTargets)"
                 Properties="Configuration=$(Configuration);PlatformName=Win32;OutputPath=$(ToolsOutputDir)">
        </MSBuild>
    

0 comments:

Post a Comment