为什么自定义构建步骤在VS2012中有效但在VS2013中不起作用?

时间:2015-04-02 20:32:58

标签: visual-studio-2013 msbuild cmake

我注意到Custom Build Steps在我的Visual Studio 2013中停止工作。例如CMAKE生成的ZERO_CHECK不起作用。我尝试了Troubleshooting Build Customizations的所有内容,但没有任何帮助。


我创建了简单的c ++控制台应用程序,将ReadMe.txt的项目类型从text更改为Custom Build Tool,并将简单命令输入到Command Line

@echo on
copy %0 test.bat
del c:\1.txt

在项目文件中,它看起来像:

  <ItemGroup>
    <CustomBuild Include="ReadMe.txt">
      <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">@echo on
copy %0 test.bat
del c:\1.txt</Command>
    </CustomBuild>
  </ItemGroup>

在Visual Studio 2012中,一切正常,文件test.bat创建,文件c:\ 1.txt已删除。但是在Visual Studio 2013中它并不起作用。 Visual Studio 2013输出:

1>Target "ComputeCustomBuildOutput: (TargetId:28)" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppBuild.targets" from project "D:\Projects\Projects\VS2013Test\CppConsole2012\CppConsole2012\CppConsole2012.vcxproj" (target "CustomBuild" depends on it):
1>Task "CreateItem" skipped, due to false condition; ('%(CustomBuildDirsToMake.OutputFileToTool)'!='') was evaluated as (''!='').
1>Task "MakeDir" (TaskId:15)
1>  Task Parameter:
1>      Directories=
1>          D:\Projects\Projects\VS2013Test\CppConsole2012\CppConsole2012\
1>                  AcceptableNonZeroExitCodes=
1>                  Command=@echo on
1>  copy %0 test.bat
1>  del c:\1.txt
1>                  LinkObjects=true
1>                  Message=Performing Custom Build Tools
1>                  MinimalRebuildFromTracking=true
1>                  Outputs=SomeText;
1>                  TrackerLogDirectory=Debug\CppConsole2012.tlog\
1>                  TreatOutputAsContent=false (TaskId:15)
1>Done executing task "MakeDir". (TaskId:15)
1>Done building target "ComputeCustomBuildOutput" in project "CppConsole2012.vcxproj".: (TargetId:28)
1>Target "CustomBuild: (TargetId:29)" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets" from project "D:\Projects\Projects\VS2013Test\CppConsole2012\CppConsole2012\CppConsole2012.vcxproj" (target "_BuildGenerateSourcesAction" depends on it):
1>Done building target "CustomBuild" in project "CppConsole2012.vcxproj".: (TargetId:29)

Visual Studio 2012输出:

1>Target "ComputeCustomBuildOutput: (TargetId:41)" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppBuild.targets" from project "D:\Projects\Projects\VS2012Test\CppConsole2012\CppConsole2012\CppConsole2012.vcxproj" (target "CustomBuild" depends on it):
1>Task "CreateItem" skipped, due to false condition; ('%(CustomBuildDirsToMake.OutputFileToTool)'!='') was evaluated as (''!='').
1>Task "MakeDir" (TaskId:27)
1>  Task Parameter:
1>      Directories=
1>          D:\Projects\Projects\VS2012Test\CppConsole2012\CppConsole2012\
1>                  AcceptableNonZeroExitCodes=
1>                  Command=@echo on
1>  copy %0 test.bat
1>  del c:\1.txt
1>                  LinkObjects=true
1>                  Message=Performing Custom Build Tools
1>                  MinimalRebuildFromTracking=true
1>                  Outputs=SomeText;
1>                  TrackerLogDirectory=Debug\
1>                  TreatOutputAsContent=false (TaskId:27)
1>Done executing task "MakeDir". (TaskId:27)
1>Done building target "ComputeCustomBuildOutput" in project "CppConsole2012.vcxproj".: (TargetId:41)
1>Target "CustomBuild: (TargetId:42)" in file "C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets" from project "D:\Projects\Projects\VS2012Test\CppConsole2012\CppConsole2012\CppConsole2012.vcxproj" (target "_BuildGenerateSourcesAction" depends on it):
1>Using "CustomBuild" task from assembly "Microsoft.Build.CppTasks.Common.v110, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>Task "CustomBuild" (TaskId:28)
1>  Task Parameter:
1>      Sources=
1>          ReadMe.txt
1>                  AcceptableNonZeroExitCodes=
1>                  Command=@echo on
1>  copy %0 test.bat
1>  del c:\1.txt
1>                  LinkObjects=true
1>                  Message=Performing Custom Build Tools
1>                  MinimalRebuildFromTracking=true
1>                  Outputs=SomeText;
1>                  TrackerLogDirectory=Debug\
1>                  TreatOutputAsContent=false (TaskId:28)
1>  Task Parameter:BuildSuffix=
1>  :VCEnd (TaskId:28)
1>  Task Parameter:TrackerLogDirectory=Debug\ (TaskId:28)
1>  Task Parameter:MinimalRebuildFromTracking=True (TaskId:28)
1>  Task Parameter:TrackFileAccess=True (TaskId:28)
1>  Task Parameter:ToolArchitecture=Native32Bit (TaskId:28)
1>  Forcing rebuild of all source files due to missing command TLog "D:\Projects\Projects\VS2012Test\CppConsole2012\CppConsole2012\Debug\custombuild.command.1.tlog". (TaskId:28)
1>  @echo on
1>  copy %0 test.bat
1>  del c:\1.txt (TaskId:28)
1>  Performing Custom Build Tools (TaskId:28)
1>          1 file(s) copied. (TaskId:28)
1>  Could Not Find c:\1.txt (TaskId:28)
1>Done executing task "CustomBuild". (TaskId:28)
1>Done building target "CustomBuild" in project "CppConsole2012.vcxproj".: (TargetId:42)

您可以在VS2013中看到部分VS2012日志不存在:

1>Using "CustomBuild" task from assembly "Microsoft.Build.CppTasks.Common.v110, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
1>Task "CustomBuild" (TaskId:28)
...
1>Done executing task "CustomBuild". (TaskId:28)

1 个答案:

答案 0 :(得分:1)

您错过了Outputs元数据。有关信息,请参阅this MSDN page

<ItemGroup>
<CustomBuild Include="ReadMe.txt">
    <Command Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@echo on
copy %0 test.bat
del c:\1.txt
    </Command>
    <Outputs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">test.bat;%(Outputs)</Outputs>
</CustomBuild>
</ItemGroup>

没有它,我会收到来自CustomBuild任务的警告

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(170,5): warning MSB8018: No outputs specified for item "ReadMe.txt". Its custom build command will be skipped. [<PATH>\SandboxCpp.vcxproj]
  @echo on
          copy %0 test.bat
          del c:\1.txt (TaskId:15)
Done executing task "CustomBuild". (TaskId:15)

我猜你没有得到Using "CustomBuild" task from assembly的打印输出,因为VS2013日志中的详细程度太低了(那里应该还有更多)。