473,386 Members | 1,828 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Conditional Assembly reference

How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release Server
build and an Oracle Release Build and the only difference between them is a
reference to a different assembly.

Is it possible to do this in VS2005?
Jan 13 '06 #1
7 13776
You will probably have to dynamically load the assemblies.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release
Server
build and an Oracle Release Build and the only difference between them is
a
reference to a different assembly.

Is it possible to do this in VS2005?

Jan 13 '06 #2
Thanks for your response. So your saying that there isn't a way to do this.
The problem is dynamically loading the assemblies won't help me because the
source wouldn't compile unless one of the two assemblies was referenced.

"Peter Rilling" wrote:
You will probably have to dynamically load the assemblies.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release
Server
build and an Oracle Release Build and the only difference between them is
a
reference to a different assembly.

Is it possible to do this in VS2005?


Jan 13 '06 #3
Well, it would help you if you wanted to code the entire thing using
reflection. Which I don't think you do.

I guess you could use reflection to create the objects, then cast them to
the appropriate interface/base class type, and reference them through that
as opposed to the actual class name.

Other then that, you just have to include all the references required for
compile.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Thanks for your response. So your saying that there isn't a way to do
this.
The problem is dynamically loading the assemblies won't help me because
the
source wouldn't compile unless one of the two assemblies was referenced.

"Peter Rilling" wrote:
You will probably have to dynamically load the assemblies.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
> How do you conditionally reference an assembly based off of the build
> configuration? Imagine a scenario where I want to have an Sql Release
> Server
> build and an Oracle Release Build and the only difference between them
> is
> a
> reference to a different assembly.
>
> Is it possible to do this in VS2005?


Jan 13 '06 #4
You're touching on what I know is the right way to do this but is not
possible in my scenario. What really needs to be done is to have
interfaces/abstract classes defined in one assembly and the main application
references only that assembly.
You can then use a plugin architecture to dynamically load the correct
assembly and create the instances behind the scenes.

The problem with my scenario is I want to shove code generated obects
(strong typed datasets) into their own assemblies and there is no way it is
productive to create base interfaces for the code-generated objects.
Especially since they change so much.

This kind of stinks but it just blows this approach out of the water for
dealing with provider generic code.

What I'm really trying to do is come up with a way to get around all the
deficienices of using strong typed datasets and table adapters while trying
to talk with two different databases. It wouldn't have been ideal but it
would have been a start to just have two different kits one for Oracle
support and one for SQL Server.

The old Visual Studios (prior to .NET) also had a way to say that even a
certain file in the project should or should not be built for a particular
build configuration. This might have worked as well.

"Marina" wrote:
Well, it would help you if you wanted to code the entire thing using
reflection. Which I don't think you do.

I guess you could use reflection to create the objects, then cast them to
the appropriate interface/base class type, and reference them through that
as opposed to the actual class name.

Other then that, you just have to include all the references required for
compile.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:B5**********************************@microsof t.com...
Thanks for your response. So your saying that there isn't a way to do
this.
The problem is dynamically loading the assemblies won't help me because
the
source wouldn't compile unless one of the two assemblies was referenced.

"Peter Rilling" wrote:
You will probably have to dynamically load the assemblies.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
> How do you conditionally reference an assembly based off of the build
> configuration? Imagine a scenario where I want to have an Sql Release
> Server
> build and an Oracle Release Build and the only difference between them
> is
> a
> reference to a different assembly.
>
> Is it possible to do this in VS2005?


Jan 13 '06 #5
"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release
Server
build and an Oracle Release Build and the only difference between them is
a
reference to a different assembly.


You can just reference both in VS. Assuming you have #if ORACLE whatever
conditional compilation sections in your code, VS should optimize away the
reference to the unused one in the build. I do this all the time with
NUnit. The NUnit reference is optimized out in release builds and I do not
distribute that DLL with the apps.

-- Alan
Jan 13 '06 #6
I figured out my own question.
Although I don't see a way to do it through the IDE you can go into the
csproj file and add an attribute called Condition to the project reference.
For example, you can do the following:

<ProjectReference Include="MyTestProject.csproj" Condition="
'$(Configuration)' == 'Oracle Release' ">
<Project>{ 7E93BE13-47DB-499F-B81F-04B19776352C} </Project>
<Name>MyTestProject</Name>
</ProjectReference>
"Peter Rilling" wrote:
You will probably have to dynamically load the assemblies.

"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release
Server
build and an Oracle Release Build and the only difference between them is
a
reference to a different assembly.

Is it possible to do this in VS2005?


Jan 13 '06 #7
Alan,

That is a great workaround. FYI: I did find a way to actually place a
condition on a reference but your way might be easier. See my other post if
you are interested in how to do it.

-- Chris

"Alan Pretre" wrote:
"Oldman" <Ol****@discussions.microsoft.com> wrote in message
news:4C**********************************@microsof t.com...
How do you conditionally reference an assembly based off of the build
configuration? Imagine a scenario where I want to have an Sql Release
Server
build and an Oracle Release Build and the only difference between them is
a
reference to a different assembly.


You can just reference both in VS. Assuming you have #if ORACLE whatever
conditional compilation sections in your code, VS should optimize away the
reference to the unused one in the build. I do this all the time with
NUnit. The NUnit reference is optimized out in release builds and I do not
distribute that DLL with the apps.

-- Alan

Jan 13 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Jouke Langhout | last post by:
Hello all! For quite some time now, I've got the following problem: Access won't close properly when a user closes the application. An ACCESS process stays active and that process can only be...
10
by: John Smith | last post by:
After reading C# documentation the Conditional attribute seemed the way to go, but after inspecting the IL it seems those methods are still there and I imagine the CLR removes them. Using #if DEBUG...
2
by: Praveen Ramesh | last post by:
Hi, Is there some kind of support for "Conditional Compilation Directives" in the aspx file? I want to enclose the Register tag as follows: #if DOTNET10 <%@ Register TagPrefix="sfwg"...
2
by: Brad | last post by:
I have one of those seemingly simple questions that evades/confuses me. I've created an assembly with bass classes (classes meant to be inherited in other assemblys). In a secondary assembly (my...
11
by: Just Me | last post by:
I have a solution containing many usercontrol projects. When I wish to reference a usercontrol in another project I can select either the project or the assembly. Does it make a difference which...
3
by: Richard Lewis Haggard | last post by:
We are having a lot of trouble with problems relating to failures relating to 'The located assembly's manifest definition with name 'xxx' does not match the assembly reference" but none of us here...
10
by: lgs.lgs | last post by:
I need to be able to support multiple versions of c#. Does the compiler define any #defines so you can tell if you are compiling for.NET 1.1 or 2.0?
2
by: Terry | last post by:
I am finally able to call my .Net object from a VB6 project (see posting 'Calling VB.Net classes from VB6', thanks to the reference Tony gave me to:...
14
by: Monty | last post by:
Hello, I have created a solution which has both a web UI and a winform UI, the latter is just for administrators. The Web UI (a Web Application Project) and the winform project both...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.