I needed to this for a solution once. I had an abstract ADO.NET-
related library that could be conditionally compiled to include
assemblies for Oracle Corp's provider, MySQL's provider or one for
PostgreSQL respectively. There was a "vanilla" that didn't reference
any of them. It was necessary to have this multiple build situation
because it was inefficient to have require non-.NET Framework
assemblies when the consumer of the library had no intention of using
them.
This is how I did it: First I retained the vanilla Debug and Release
builds. The former required all assemblies. The latter required only
System.Data and System.Data.OracleClient - which come included in the
Framework. Additionally I created Release MySQL, Release ODAC and
Release PostgreSQL builds each with a helpful conditional compile
symbols of MYSQL, ODAC and POSTGRESQL respectively. Conditional
compile symbols are set from the Properties of the project.
There was only a remarkably small amount of #if wrappers in my code on
those helpful conditional compile symbols for code depending on non-
Framework assemblies.
However, this is not enough. To this point, all I had done was
conditionally *compile* certain parts of my code. I was still
unconditionally referencing my non-Framework assemblies. In order to
resolve this, I had to roll my sleeves up and tweek the .csproj xml
file directly, which I include below. I cobbled together the know-how
on doing this from a variety of links that I no longer have. But you
can probably do a search on MSDN and Google for more information based
on my post. This is from my Visual Studio 2005 Pro edition C#
project.
<Project DefaultTargets="Build" xmlns="
http://schemas.microsoft.com/
developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</
Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{whatever}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>com.aastra.us.OmniData</RootNamespace>
<AssemblyName>MyProject.CoreLibrary</AssemblyName>
<ApplicationIcon>favicon.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|
AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>TRACE;DEBUG;ODAC MYSQL POSTGRESQL</
DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release|AnyCPU' ">
<DebugType>none</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release ODAC|AnyCPU' ">
<OutputPath>bin\Release ODAC\</OutputPath>
<DefineConstants>TRACE;ODAC</DefineConstants>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release MYSQL|AnyCPU' ">
<OutputPath>bin\Release MYSQL\</OutputPath>
<DefineConstants>TRACE;MYSQL</DefineConstants>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' ==
'Release POSTGRESQL|AnyCPU' ">
<OutputPath>bin\Release POSTGRESQL\</OutputPath>
<DefineConstants>TRACE;POSTGRESQL</DefineConstants>
<Optimize>true</Optimize>
<DebugType>none</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
</PropertyGroup>
<ItemGroup>
<Reference Include="Oracle.DataAccess, Version=2.102.2.20,
Culture=neutral, PublicKeyToken=89b483f429c47342,
processorArchitecture=x86" Condition="'$(Configuration)'=='DEBUG'OR'$
(Configuration)'=='Release ODAC'">
<HintPath>..\lib\Oracle.DataAccess.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MySql.Data, Version=5.0.2.0, Culture=neutral,
PublicKeyToken=c5687fc88969c44d, processorArchitecture=MSIL"
Condition="'$(Configuration)'=='DEBUG'OR'$(Configuration)'=='Release
MYSQL'">
<HintPath>..\lib\MySql.Data.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Npgsql, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=5d8b90d52f46fda7, processorArchitecture=MSIL"
Condition="'$(Configuration)'=='DEBUG'OR'$(Configuration)'=='Release
POSTGRESQL'">
<HintPath>..\lib\Npgsql.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Mono.Security, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=0738eb9f132ed756" Condition="'$
(Configuration)'=='DEBUG'OR'$(Configuration)'=='Release POSTGRESQL'">
<HintPath>..\lib\Mono.Security.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.configuration" />
<Reference Include="System.Data" />
<Reference Include="System.Data.OracleClient" />
<Reference Include="System.Transactions" />
<Reference Include="System.Web" />
<Reference Include="System.Xml" />
</ItemGroup>
...(uninteresting parts intentionally removed)
</Project>
I don't recommend editing your .csproj file directly, but you don't
have that much to lose.
Michael O
http://blog.crisatunity.com