简体   繁体   English

程序集HintPaths的C#csproj文件“选择”元素

[英]C# csproj file “Choose” element for assembly HintPaths

Is it possible to use the Choose/When/Otherwise elements on a reference hintpath? 是否可以在参考提示路径上使用“选择/何时/否则”元素?

Something like this: 像这样:

<ItemGroup>
  <Reference Include="SharedLib...">
<SpecificVersion>False</SpecificVersion>
<Choose>
  <When Condition="Exists('..\..\SharedLib\bin\Debug')">
        <HintPath>..\..\SharedLib\bin\Debug\SharedLib.dll</HintPath>
  </When>
  <Otherwise>
         <HintPath>.\SharedLib.dll</HintPath>
  </Otherwise>
</Choose>
  </Reference>
</ItemGroup>

But I get errors like ...required attribute "Include" is empty or missing from element "ItemGroup" 但是我收到类似...的错误,...必需属性“ Include”为空或元素“ ItemGroup”中缺少

Other attempts/version have yielded similar errors such as ...The "Choose" item metadata name is reserved and cannot be used. 其他尝试/版本也产生了类似的错误,例如...“选择”项元数据名称已保留,无法使用。

This makes me think I canNOT use the "Choose" element INSIDE of an ItemGroup element. 这让我觉得我不能使用ItemGroup元素的“ Choose”元素。

I welcome clarification. 我欢迎澄清。 See attached samples of the errors. 请参见附件中的错误示例。 Visual Studio csproj Errors when loading project 加载项目时出现Visual Studio csproj错误

I don't think you can put just the HintPath in the Choose. 我认为您不能仅将“ HintPath”放入“选择”中。 You have to put the entire ItemGroup within the When and Otherwise. 您必须将整个ItemGroup放在“何时”或“否则”中。 Like this: 像这样:

<Choose>
  <When Condition="Exists('..\..\SharedLib\bin\Debug')">
    <ItemGroup>
      <Reference Include="SharedLib...">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>..\..\SharedLib\bin\Debug\SharedLib.dll</HintPath>
      </Reference>
    </ItemGroup>
  </When>
  <Otherwise>
    <ItemGroup>
      <Reference Include="SharedLib...">
        <SpecificVersion>False</SpecificVersion>
        <HintPath>.\SharedLib.dll</HintPath>
      </Reference>
    </ItemGroup>
  </Otherwise>
</Choose>

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM