在目标中设置 CustomBuild 的 OutputItemType 不起作用

Setting CustomBuild's OutputItemType in a target doesn't work

如果您像这样在自定义构建工具中设置“将输出添加到项目类型”属性,

它将在 .vcxproj 文件中添加以下行:

<OutputItemType>ClCompile</OutputItemType>

但是,当我定义自己的目标并尝试使用它时,它不起作用。

(...)

<Target Name="__SECompile" BeforeTargets="PreBuildEvent">

    <ItemGroup>
        <_SECompileMetadataSet Include="@(SECompile)">
            <Message>Processing %(Identity)</Message>
            <Outputs>$(ProjectDir)intermediate\%(Identity)</Outputs>
            <Command>python (path to a python script) "%(FullPath)" "$(ProjectDir)intermediate\%(Identity)"</Command>
            <OutputItemType>ClCompile</OutputItemType>
            <LinkObjects>false</LinkObjects>
        </_SECompileMetadataSet>
    </ItemGroup>

(...)
(Below is just a copy-paste from Microsoft.CppCommon.targets)

    <!-- Get out of date items (will create tlogs for all SECompile items) -->
    <GetOutOfDateItems
      Condition                 ="'$(SelectedFiles)' == ''"
      Sources                   ="@(_SECompileMetadataSet)"
      OutputsMetadataName       ="Outputs"
      DependenciesMetadataName  ="AdditionalInputs"
      CommandMetadataName       ="Command"
      TLogDirectory             ="$(TLogLocation)"
      TLogNamePrefix            ="SECompile"
      CheckForInterdependencies ="true"
      >
      <Output TaskParameter="OutOfDateSources" ItemName="_SECompile"/>
    </GetOutOfDateItems>

    <!-- Buidl items which can be built in parallel (ignored for selected files build)-->
    <ItemGroup Condition="'$(SelectedFiles)' == ''">
      <_ParallelSECompile Include="@(_SECompile)" />
    </ItemGroup>

    <ParallelCustomBuild
      Condition       ="'@(_ParallelSECompile)' != ''"
      Sources         ="@(_ParallelSECompile)"
      MaxProcesses    ="0"
      MaxItemsInBatch ="0"
      AcceptableNonZeroExitCodes  =""
    />

(...)

python 脚本是 运行 并且正在输出消息,因此其他属性正在运行。但是 OutputItemType 不起作用。

我想做的基本上是做与 CustomBuild 完全相同的事情,其参数预定义有特定值。

所以问题是: 为什么当您在目标中手动设置它时它不起作用,而它应该与 vcxproj 文件中设置的相同?

通过 Visual Studio 反馈得到了答案。 放

<ItemGroup Condition="'@(_SECompile)' != ''"> <ClCompile Include="%(_SECompile.Outputs)" Condition="'%(_SECompile.ExcludedFromBuild)' != 'true'" /> </ItemGroup>

在目标中会起作用。

原文link:https://developercommunity.visualstudio.com/t/Setting-CustomBuilds-OutputItemType-in/1452940?entry=myfeedback&ref=native&refTime=1624191549072&refUserId=95d48ba8-b75f-4896-8bf5-5745bf012b77