gpt4 book ai didi

visual-studio - BuildingInsideVisualStudio 属性值不适用于文件引用和项目引用条件

转载 作者:行者123 更新时间:2023-12-04 23:06:37 27 4
gpt4 key购买 nike

我正在尝试使用 BuildingInVsideisualStudio 属性在 csproj 中添加对相同 dll 的项目和文件引用。但是当它们一起在 csproj 中时,只会拾取文件引用。如果我删除文件引用,它会选择 csproj。我试过交换订单,但没有运气。任何想法为什么这不起作用?

这是基本思想:

<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == false">
<Reference Include="MyNamespace.Mine">
<HintPath>..\$(OutDir)\MyNamespace.Mine.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == '' Or '$(BuildingInsideVisualStudio)' == true">
<ProjectReference Include="..\MyNamespace.Mine.csproj">
<Project>{GUID}</Project>
<Name>MyNamespace.Mine</Name>
</ProjectReference>
</ItemGroup>

Someone else也走上了这条路,但似乎有 some caveats .由于我的构建过程无法更改,因此我需要有条件地执行此操作。使用文件引用迫使我丢失转到定义和查找所有引用(抱歉,我也无法安装 ReSharper 来解决这个问题)。

最佳答案

我看到两个问题:

  • 你没有考虑到$(BuildingInsideVisualStudio)可以为空( '' )。对于第一个条件使用:
    <ItemGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
  • 始终用单引号将两个操作数括起来:
    <ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">


  • MSDN reference:

    Single quotes are not required for simple alphanumeric strings or boolean values. However, single quotes are required for empty values.



    更新:

    可能是一个长镜头,但您可以尝试在属性定义上使用条件:
    <PropertyGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'"><!-- In CMD -->
    <ReferenceInclude>MyNamespace.Mine"</ReferenceInclude>
    <ReferenceIncludePath>..\$(OutDir)\MyNamespace.Mine.dll</ReferenceIncludePath>
    </PropertyGroup>
    <PropertyGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'"><!-- In VS -->
    <ProjectReferenceInclude>..\MyNamespace.Mine.csproj</ProjectReferenceInclude>
    <ProjectReferenceIncludeId>{GUID}</ProjectReferenceIncludeId>
    </PropertyGroup>

    因此,引用将有条件地解析:
    <ItemGroup>
    <Reference Include="$(ReferenceInclude)">
    <HintPath>$(ReferenceIncludePath)</HintPath>
    </Reference>
    </ItemGroup>
    <ItemGroup>
    <ProjectReference Include="$(ProjectReferenceInclude)">
    <Project>$(ProjectReferenceIncludeId)</Project>
    <Name>%(ProjectReferenceInclude.MSBuildProjectName)</Name>
    </ProjectReference>
    </ItemGroup>

    关于visual-studio - BuildingInsideVisualStudio 属性值不适用于文件引用和项目引用条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10738246/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com