简体   繁体   English

MSBuild ItemGroup 条件项目参考

[英]MSBuild ItemGroup Condition Project Reference

I'm trying to include a Project Reference based on a value in the ItemGroup Condition我正在尝试根据 ItemGroup 条件中的值包含项目参考

This is what I have tried.这是我尝试过的。 With BeforeTargets Compile it does recognize the project but it won't let me build the project.使用 BeforeTargets Compile 它确实可以识别该项目,但它不会让我构建该项目。

<Target Name="ErpSystemToUse" BeforeTargets="Compile">
    <ReadLinesFromFile File="$(MSBuildProjectDirectory)\..\..\Presentation\Nop.Web\App_Data\erpSystemToUse.txt">
        <Output TaskParameter="Lines" ItemName="ValueTextFile" />
    </ReadLinesFromFile>
    <Message Text="@(ValueTextFile)" Importance="high" />

    <ItemGroup Condition="'@(ValueTextFile)' == 'Twinfield'">
        <ProjectReference Include="..\..\Dimerce.Twinfield\Dimerce.Plugin.Misc.Twinfield\Dimerce.Plugin.Misc.Twinfield.csproj" />
    </ItemGroup>
</Target>

Is what I am trying to achieve possible?我想要实现的目标是可能的吗?

I have a project where I had to inspect output of System.Reflection.Emit .我有一个项目,我必须检查System.Reflection.Emit的 output 。 Decided to include package reference only when appropriate constant is defined仅在定义了适当的常量时才决定包含 package 参考

Main difference is that target executes before CollectPackageReferences .主要区别在于 target 在CollectPackageReferences之前执行。 Try to change BeforeTargets .尝试更改BeforeTargets

Also use Inputs and Outputs to reduce build time还使用InputsOutputs来减少构建时间

  <Target Name="IncludeIlPackReference"
          Inputs="$(DefineConstants)" Outputs="@(PackageReference)"
          BeforeTargets="CollectPackageReferences"
          Condition="$(DefineConstants.Contains('TRACE_GENERATED_IL'))">
    <ItemGroup>
      <PackageReference Include="Lokad.ILPack" Version="0.1.6" />
    </ItemGroup>
  </Target>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# - MSBuild 参考 - 复制到 CopyToOutputDirectory 的所有项目<itemgroup></itemgroup> - C# - MSBuild reference - Copy to CopyToOutputDirectory all items of <itemGroup> 从MSBuild XML获取ItemGroup集合及其项目 - Getting ItemGroup collection and their Items from MSBuild xml 如何对带引号的文件的ItemGroup列表进行转义-MSBuild - How to escape an ItemGroup list of files with quotes - MSBuild 在MsBuild中,PropertyGroup和ItemGroup之间有什么区别 - In MsBuild, what's the difference between PropertyGroup and ItemGroup 使用MSBuild构建.csproj而不使用项目引用 - Build .csproj with MSBuild without project reference ItemGroup项目范围,或者“为什么MSBuild讨厌我?” - ItemGroup Item scope, alternatively “Why does MSBuild hate me?” 为什么MsBuild的ItemGroup-&gt; EndWith无法用于&#39;.exe&#39;? - Why is MsBuild's ItemGroup->EndWith not working for '.exe'? Silverlight项目文件的ItemGroup中的WCFMetadata标记 - WCFMetadata tag in ItemGroup of silverlight project file Msbuild无法使用间接引用System.Runtime来构建网站项目 - Msbuild fails building website project with an indirect reference to System.Runtime MsBuild StartsWith 不评估条件? - MsBuild StartsWith not Evaluating In Condition?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM