我有一个编译C ++程序的.vcxproj文件。我想创建第二个MSBuild项目文件,通过运行它来测试程序,但仅限于自上次成功测试后程序已重建。如何从第二个项目文件访问程序的“TargetPath”?
如果我可以从.vcxproj文件中将TargetPath作为“项目”访问,那么测试人员项目文件将如下所示:
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="Build" Inputs="@(TargetPath)" Outputs="@(TargetPath->'%(filename).test-passed)'">
<Exec Command="@(TargetPath)" />
<Touch Files="@(TargetPath->'%(filename).test-passed)'" />
</Target>
</Project>
我想使用程序编译中的单独项目文件来执行测试,以便在Visual Studio中更轻松地选择构建和测试或构建和调试,而不会增加构建配置。
答案 0 :(得分:1)
可以使用MSBuild任务运行由单独的.vcxproj编译的本机程序。使用<Output>
元素创建一个带有&#34; TargetOutputs&#34;的项目。来自C ++应用程序构建。但是,如果你正在构建一个&#34; native&#34;程序,&#34; TargetOutputs&#34;通常是空白的。在这种情况下,使用&#34; GetNativeTargetPath&#34;获取输出路径的目标。以下项目.vcxproj文件适用于Visual Studio。它构建了test_build.vcxproj。如果test_build.exe文件自上次成功运行后已更改,则运行该文件。
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{80DB0D71-72E0-4FB1-B53F-EFB858A1D5A8}</ProjectGuid>
<Keyword>Win32Proj</Keyword>
<RootNamespace>nordic_test_run</RootNamespace>
</PropertyGroup>
<PropertyGroup>
<ConfigurationType>Application</ConfigurationType>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ItemGroup>
<ProjectReference Include="test_build.vcxproj" />
</ItemGroup>
<Target Name="BuildExecutable">
<MSBuild Projects="@(ProjectReference)" Targets="Build" BuildInParallel="True" />
<MSBuild Projects="@(ProjectReference)" Targets="GetNativeTargetPath" BuildInParallel="True">
<Output TaskParameter="TargetOutputs" ItemName="NativeTests" />
</MSBuild>
</Target>
<Target Name="Build" DependsOnTargets="BuildExecutable" Inputs="@(NativeTests)" Outputs="@(NativeTests->'%(filename).test-passed')">
<Exec Command="@(NativeTests)" />
<Touch Files="@(TestTargets->'%(filename).test-passed')" />
</Target>
</Project>