【问题标题】:Error using MSBuild tokens in PropertyGroup在 PropertyGroup 中使用 MSBuild 令牌时出错
【发布时间】:2009-08-19 09:47:49
【问题描述】:

我正在尝试设置一些在我的 MSBuild 脚本中多次使用的属性。我有以下属性部分:

<PropertyGroup>
    <BuildDependsOn>$(BuildDependsOn); MyAfterBuild </BuildDependsOn>
    <SubstitutionsFilePath>$(ProjectDir)app.config.substitutions.xml </SubstitutionsFilePath>
    <AppConfig>$(TargetPath).config</AppConfig>
    <HostConfig>$(TargetDir)$(TargetName).vshost.exe.config</HostConfig>
</PropertyGroup>

当我运行它时,我收到以下错误:

The expression "@(TargetPath).config" cannot be used in this context. Item lists cannot be concatenated with other strings where an item list is expected. Use a semicolon to separate multiple item lists.

我不明白这个错误,因为使用 $(BuildDependsOn)$(ProjectDir) 工作正常。而且我知道$(TargetXXX) 值会正确生成,因为当我将它们直接放入下面的任务部分时,它们可以正常工作。

【问题讨论】:

    标签: msbuild


    【解决方案1】:

    这个问题的原因是TargetDir被定义为一个项目列表,而不是一个属性;大概是为了迎合您的输出分布在多个输出目录中的场景?

    我遇到了同样的问题,并设法通过使用 $(OutDir) 属性而不是 $(TargetDir) 来解决它。

    OutDir 属性在 Microsoft.Common.Targets(第 100-102 行)中定义为项目文件中定义的 OutputPath 的规范化版本。)

    【讨论】:

      【解决方案2】:

      首先尝试使用 /v:diag 选项运行您的构建,这将输出更多信息并为您提供有关构建失败部分的线索。

      线索可能在 PrepareForBuild 目标的 Microsoft.Common.targets 文件(位于 %SystemRoot%\Microsoft.NET\Framework\v2.0.50727)中:

         <!-- 
          These CreateProperty calls are required because TargetDir and TargetPath are defined 
          to contain an item list. We want that item list to be expanded so that it can be used
          as a regular property value and not as an item-list-with-transform.
          -->
          <CreateProperty Value="$(TargetDir)">
              <Output TaskParameter="Value" PropertyName="TargetDir" />
          </CreateProperty>
      
          <CreateProperty Value="$(TargetPath)">
              <Output TaskParameter="Value" PropertyName="TargetPath" />
          </CreateProperty>
      

      【讨论】:

        【解决方案3】:

        在我看来,这似乎是一个错误,您可以通过https://connect.microsoft.com/feedback/Search.aspx?SiteID=210 报告它。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2019-01-07
          • 1970-01-01
          • 2018-12-25
          • 2018-10-29
          • 2011-03-18
          相关资源
          最近更新 更多