【问题标题】:Setting CustomBuild's OutputItemType in a target doesn't work在目标中设置 CustomBuild 的 OutputItemType 不起作用
【发布时间】:2021-05-29 22:46:42
【问题描述】:

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

它将在.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文件中设置的相同时它不起作用?

【问题讨论】:

  • 或许您可以尝试将其添加到ItemMetadata group
  • @DylanZhu-MSFT 是的,我忘记更新了,我在发布这个问题后已经尝试过了。也不行。
  • 您可以尝试将ItemGroup移出Target
  • @DylanZhu-MSFT 感谢您的建议。但是,这也不起作用......

标签: visual-studio msbuild msbuild-target


【解决方案1】:

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

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

在目标中会起作用。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-09
    • 1970-01-01
    • 2011-07-16
    • 2016-06-21
    • 1970-01-01
    • 1970-01-01
    • 2013-09-18
    • 1970-01-01
    相关资源
    最近更新 更多