问题描述
我正在尝试使用BuildingInVsideisualStudio属性在csproj中添加对同一个dll的项目和文件引用.但是,当它们一起放在csproj中时,只会选择文件引用.如果删除文件引用,它将使用csproj.我尝试过交换订单,但是没有运气.任何想法为什么这不起作用?
I am trying to add a project and file reference to the same dll in the csproj with the BuildingInVsideisualStudio property. But when they are in the csproj together, only the file reference is picked up. If I remove the file reference, it picks up the csproj. I have tried swapping the order, but no luck. Any ideas why this doesn't work?
这是基本概念:
<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>
其他人也走了这条路,但是似乎有一些警告.由于我的构建过程无法更改,因此需要有条件地执行此操作.使用文件引用会迫使我丢失转到定义和查找所有引用"(很抱歉,但是我也无法安装ReSharper来解决此问题).
Someone else has gone down this path, too, but it appears there are some caveats. I need to do this conditional because of my build process, which cannot change. Using the file reference forces me to lose the Go to Definition and Find All References (sorry, but I cannot install ReSharper to solve this either).
推荐答案
假设经过一番试验,我正确理解了这个问题,似乎用不同的方式命名它们可以解决大多数问题. msbuild将遵守条件并使用程序集引用,VS会在解决方案资源管理器中同时显示它们,但会像项目类型一样预先构建引用,并且无需R#即可保持goto定义.条件导入是值得研究的其他东西,但我还没有尝试过.
Assuming I understood the question correctly after bit of experimentation it seems that naming them differently would solve most of the problems; msbuild would respect the condition and use assembly reference, VS would display them both in solution explorer but would prebuilt the reference as if it is project kind and would keep goto-definition without R# working. Conditional import is something else worth looking into but I haven't tried it.
<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>
这篇关于BuildingInsideVisualStudio属性值不适用于文件引用和有条件的项目引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!