Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual studio 2010 conditional references

We have multiple products here that shared some common libraries. These libraries are part of a separate solution (so they can be built by TFS independently), but the problem is during development, one has to modify the common library, compile it to binary, copy it to the common location, compile the product solution.

In order to avoid this actually I am wondering if its possible to have conditional references, so for a debug configuration, I would reference them as project references, while in release configuration they would be binary references.

like image 935
np-hard Avatar asked Jun 29 '11 15:06

np-hard


2 Answers

You should be able to do this with conditional constructs by editing the project file directly (VS IDE won't do this for you).

For example, you might do something like this using the "Choose" element:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" >
    <PropertyGroup>
        <!-- ... --> 
    </PropertyGroup>
    <Choose>

        <When Condition=" '$(Configuration)'=='Debug' ">
            <ItemGroup>
                <ProjectReference Include="..\stuff\MyStuff.csproj">
                    <Project>{4c7bbe47-8d84-45d4-95f0-f640ba59563c}</Project>
                    <Name>MyStuff</Name>
                </ProjectReference>
            </ItemGroup>
        </When>

        <When Condition=" '$(Configuration)'=='Retail' ">
            <ItemGroup>
                <Reference Include="MyStuff.dll" />
            </ItemGroup>
        </When>

    </Choose>
    <!-- Rest of Project -->
</Project>

MSDN has more information about using conditional constructs.

like image 166
Matt Avatar answered Oct 20 '22 07:10

Matt


You might want to have a look at NuGet:

NuGet

NuGet is a free, open source developer focused package management system for the .NET platform intent on simplifying the process of incorporating third party libraries into a .NET application during development.

(where you would be the third party yourself in this case)

Note: This would not give you conditional references, but it would ease updating the common components.

like image 41
Dirk Vollmar Avatar answered Oct 20 '22 07:10

Dirk Vollmar