2012-12-03 55 views
0

运行我用我自己的配置编译我的GTests:附加VS2010调试器GTEST MSBuild中

<ProjectConfiguration Include="Test|Win32"> 
    <Configuration>Debug</Configuration> 
    <Platform>Win32</Platform> 
</ProjectConfiguration> 

我运行使用由目标

<Target Name="RunTests"> 
    <Message Text="Configuration: $(Configuration)" Importance="High" /> 
    <Exec Command="..\$(Configuration)\@(BuildProjectFile->'%(Filename)').exe" /> 
    </Target> 

我想运行我GTEST定制我的GTests使用VS2010而不是将其作为自己的可执行文件运行。我想要使​​用VS2010调试器来调试我的测试。

是否有正确的任务开始我的编译,以便调试器选择它,或者我是否必须返回一些东西到VS2010,以便它自己开始执行?

回答

0

通过使用Returns="@(ManagedTargetPath)" VS获取可执行的是应该开始。

而不是通过Exec任务启动测试任务目标应该是Build with Debugging启用,TargetPath应该返回到VS执行。

以下示例重定向传入构建调用,以执行unittests,并使用VS2010的构建机制启动它们。

(我现在不明白,为什么在* .cc的文件断点被忽略,在* .c文件的那些不忽略 - 可能是一个巧合)

<?xml version="1.0" encoding="utf-8"?> 
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 
    <ItemGroup Label="ProjectConfigurations"> 
    <ProjectConfiguration Include="Debug|Win32"> 
     <Configuration>Debug</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Release|Win32"> 
     <Configuration>Release</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    </ItemGroup> 
    <ItemGroup> 
    <ClCompile Include="main.c" /> 
    <ClCompile Include="Source\A.c" /> 
    <ClCompile Include="Source\A_unittest.cc" /> 
    </ItemGroup> 
    <ItemGroup> 
    <ClInclude Include="main.h" /> 
    </ItemGroup> 
    <PropertyGroup Label="Globals"> 
    <ProjectGuid>{7506F0B9-7FA3-4E1E-8EB5-A1819E232C59}</ProjectGuid> 
    <RootNamespace>STACKOVERFLOW</RootNamespace> 
    </PropertyGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration"> 
    <ConfigurationType>Application</ConfigurationType> 
    <UseDebugLibraries>true</UseDebugLibraries> 
    <CharacterSet>MultiByte</CharacterSet> 
    </PropertyGroup> 
    <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 
    <ConfigurationType>Application</ConfigurationType> 
    <UseDebugLibraries>false</UseDebugLibraries> 
    <WholeProgramOptimization>true</WholeProgramOptimization> 
    <CharacterSet>MultiByte</CharacterSet> 
    </PropertyGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 
    <ImportGroup Label="ExtensionSettings"> 
    </ImportGroup> 
    <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 
    </ImportGroup> 
    <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 
    <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> 
    </ImportGroup> 
    <PropertyGroup Label="UserMacros" /> 
    <PropertyGroup /> 
    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 
    <ClCompile> 
     <WarningLevel>Level3</WarningLevel> 
     <Optimization>Disabled</Optimization> 
    </ClCompile> 
    <Link> 
     <GenerateDebugInformation>true</GenerateDebugInformation> 
    </Link> 
    </ItemDefinitionGroup> 
    <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 
    <ClCompile> 
     <WarningLevel>Level3</WarningLevel> 
     <Optimization>MaxSpeed</Optimization> 
     <FunctionLevelLinking>true</FunctionLevelLinking> 
     <IntrinsicFunctions>true</IntrinsicFunctions> 
    </ClCompile> 
    <Link> 
     <GenerateDebugInformation>true</GenerateDebugInformation> 
     <EnableCOMDATFolding>true</EnableCOMDATFolding> 
     <OptimizeReferences>true</OptimizeReferences> 
    </Link> 
    </ItemDefinitionGroup> 
    <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 
    <ImportGroup Label="ExtensionTargets"> 
    </ImportGroup> 
    <Target 
    Name="NormalBuild" 
    Condition=" '$(_InvalidConfigurationWarning)' != 'true' " 
    DependsOnTargets="_DetermineManagedStateFromCL;CustomBeforeBuild;$(BuildDependsOn)" 
    Returns="@(ManagedTargetPath)"> 
    <ItemGroup> 
     <ManagedTargetPath Include="$(TargetPath)" Condition="'$(ManagedAssembly)' == 'true'" /> 
    </ItemGroup> 
    </Target> 

    <ItemGroup Label="ProjectConfigurations"> 
    <ProjectConfiguration Include="Debug|Win32"> 
     <Configuration>Debug</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Release|Win32"> 
     <Configuration>Release</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    <ProjectConfiguration Include="Test|Win32"> 
     <Configuration>Debug</Configuration> 
     <Platform>Win32</Platform> 
    </ProjectConfiguration> 
    </ItemGroup> 

    <Target Name="Build" 
    Returns="@(ManagedTargetPath)"> 
    <MSBuild Projects="STACKOVERFLOW.vcxproj" Targets="NormalBuild" Properties="Configuration=Test" /> 
    </Target> 

    <Target Name="CustomBeforeBuild"> 
    <ItemGroup Condition="'$(Configuration)' == 'Test'"> 
     <ClCompile Remove="*main.c*" /> 
     <ClCompile Include="c:/gtest/*.c*" /> 
    </ItemGroup> 
    </Target> 

</Project>