Conditional Assembly reference

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Oldman

    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?
  • Peter Rilling

    #2
    Re: Conditional Assembly reference

    You will probably have to dynamically load the assemblies.

    "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
    news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=blue]
    > 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?[/color]


    Comment

    • Oldman

      #3
      Re: Conditional Assembly reference

      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:
      [color=blue]
      > You will probably have to dynamically load the assemblies.
      >
      > "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
      > news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=green]
      > > 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?[/color]
      >
      >
      >[/color]

      Comment

      • Marina

        #4
        Re: Conditional Assembly reference

        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" <Oldman@discuss ions.microsoft. com> wrote in message
        news:B5BA3DAE-C42C-4021-9A4B-9CC0B9113A91@mi crosoft.com...[color=blue]
        > 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:
        >[color=green]
        >> You will probably have to dynamically load the assemblies.
        >>
        >> "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
        >> news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=darkred]
        >> > 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?[/color]
        >>
        >>
        >>[/color][/color]


        Comment

        • Oldman

          #5
          Re: Conditional Assembly reference

          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:
          [color=blue]
          > 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" <Oldman@discuss ions.microsoft. com> wrote in message
          > news:B5BA3DAE-C42C-4021-9A4B-9CC0B9113A91@mi crosoft.com...[color=green]
          > > 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:
          > >[color=darkred]
          > >> You will probably have to dynamically load the assemblies.
          > >>
          > >> "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
          > >> news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.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?
          > >>
          > >>
          > >>[/color][/color]
          >
          >
          >[/color]

          Comment

          • Alan Pretre

            #6
            Re: Conditional Assembly reference

            "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
            news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=blue]
            > 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.[/color]

            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


            Comment

            • Oldman

              #7
              Re: Conditional Assembly reference

              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:

              <ProjectReferen ce Include="MyTest Project.csproj" Condition="
              '$(Configuratio n)' == 'Oracle Release' ">
              <Project>{ 7E93BE13-47DB-499F-B81F-04B19776352C} </Project>
              <Name>MyTestPro ject</Name>
              </ProjectReferenc e>


              "Peter Rilling" wrote:
              [color=blue]
              > You will probably have to dynamically load the assemblies.
              >
              > "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
              > news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=green]
              > > 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?[/color]
              >
              >
              >[/color]

              Comment

              • Oldman

                #8
                Re: Conditional Assembly reference

                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:
                [color=blue]
                > "Oldman" <Oldman@discuss ions.microsoft. com> wrote in message
                > news:4C7D9868-1FA4-45CC-8E65-4599B2435505@mi crosoft.com...[color=green]
                > > 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.[/color]
                >
                > 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
                >
                >
                >[/color]

                Comment

                Working...