Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BuildingInsideVisualStudio Property Value Not Working With File Reference and Project Reference Conditional

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).

like image 841
kevindaub Avatar asked May 24 '12 13:05

kevindaub


1 Answers

Two problems I see:

  1. You didn't take into account that $(BuildingInsideVisualStudio) can be empty (''). For the first condition use:

    <ItemGroup Condition="'$(BuildingInsideVisualStudio)' != 'true'">

  2. 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>
like image 193
KMoraz Avatar answered Nov 15 '22 07:11

KMoraz