kev*_*aub 4 msbuild csproj visual-studio
我正在尝试使用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>
Run Code Online (Sandbox Code Playgroud)
其他人也走了这条道路,但似乎有一些警告.因为我的构建过程无法改变,所以我需要这样做.使用文件引用迫使我失去Go to Definition和Find All References(抱歉,但我也无法安装ReSharper来解决这个问题).
我看到两个问题:
你没有考虑到$(BuildingInsideVisualStudio)可以为空('').对于第一个条件使用:
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
始终用单引号括住两个操作数:
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' == 'true'">
简单的字母数字字符串或布尔值不需要单引号.但是,空值需要单引号.
更新:
可能是一个长镜头,但你可以尝试使用属性定义的条件:
<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>
Run Code Online (Sandbox Code Playgroud)
所以引用将有条件地解决:
<ItemGroup>
<Reference Include="$(ReferenceInclude)">
<HintPath>$(ReferenceIncludePath)</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(ProjectReferenceInclude)">
<Project>$(ProjectReferenceIncludeId)</Project>
<Name>%(ProjectReferenceInclude.MSBuildProjectName)</Name>
</ProjectReference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
假设我在经过一些实验后正确理解了这个问题,那么以不同的方式命名它们似乎可以解决大多数问题;msbuild 会尊重条件并使用程序集引用,VS 会在解决方案资源管理器中显示它们,但会预构建引用,就好像它是项目类型一样,并且会在 R# 不工作的情况下保持 goto-definition。条件导入是其他值得研究的东西,但我还没有尝试过。
<ItemGroup>
<ProjectReference Include="..\ClassLibrary1\ClassLibrary1.csproj" Condition="'$(Foo)'=='Bar1'">
<Project>{FD0E01BC-7777-4620-9EF2-5F60804B3173}</Project>
<Name>ClassLibrary1-ProjRef</Name>
</ProjectReference>
<Reference Include="ClassLibrary1" Condition="'$(Foo)'=='Bar2'">
<Name>ClassLibrary1-AssRef</Name>
<HintPath>..\ClassLibrary1\bin\Debug\ClassLibrary1.dll</HintPath>
</Reference>
</ItemGroup>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7704 次 |
| 最近记录: |