visual studio 2010 conditional references
Asked Answered
R

2

26

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.

Romulus answered 29/6, 2011 at 15:15 Comment(3)
No nice way that I am aware of; in the past I have used multiple solutions... a "Master" solution that references everything if you are making major architectural changes, and then separate project solutions if just working on an individual project. Generally, a PITA.Warsle
You can do this by modifying the .csproj file manually.Soothsayer
You can do this by modifying your building process. Use a tool like MsBuild.Ical
C
40

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.

Crispa answered 29/6, 2011 at 15:31 Comment(2)
do these projects have to part of the solution also ?Romulus
I believe so, but in the "release" case it should still be fine. They should show up as not being found, which wouldn't matter because in the release build they're not actually being referenced.Crispa
C
4

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.

Cylindrical answered 29/6, 2011 at 15:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.