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?
Here is the basic idea:
<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 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).
Two problems I see:
You didn't take into account that $(BuildingInsideVisualStudio)
can be empty (''
). For the first condition use:
<ItemGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">
Always surround both operands with single quotes:
<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.
UPDATE:
May be a long shot, but you can try using conditions on the property defintions:
<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>
So the references will get resolved conditionally:
<ItemGroup>
<Reference Include="$(ReferenceInclude)">
<HintPath>$(ReferenceIncludePath)</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(ProjectReferenceInclude)">
<Project>$(ProjectReferenceIncludeId)</Project>
<Name>%(ProjectReferenceInclude.MSBuildProjectName)</Name>
</ProjectReference>
</ItemGroup>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With