0

Suppose I have a class library with some conditional compilation, that eventually gets built to MyPortable.dll and MyPortable.X.dll, where the latter is the version compiled with the conditional enabled.

Then I have my "Core" project which references "MyPortable.dll". So far so good.

However, my problem lies in the third project (the "App"), which has a reference to "Core", but needs to use "MyPortable.X.dll" (which is a different build that "Core" uses), but because "Core" is linked against to "MyPortable.dll", my "App" ends using that same version as well, instead of "MyPortable.X.dll".

Is there any way to do that? The code is something like this:

MyPortable

namespace MyPortable
{
    public class Person {
        public string Name { get; set; }
    }

    public class Something {
        public List<Person> GetPersons() {
            List<Person> l = new List<Person>();
            l.Add(new Person { Name = "Name 1" });

#if PLATFORM_X
            l.Add(new Person { Name = "Name 2" });
#endif

            return l;
        }
    }
}

I first compile MyPortable without "PLATFORM_X" enabled, and then I compile again, this time with the flag turned ON. File references are below (note that I am referencing Core.csproj directly):

Core\References\MyPortable.dll
App\
    \References\Core.csproj
    \References\MyPortable.X.dll
Rafael Steil
  • 4,538
  • 4
  • 25
  • 30

2 Answers2

1

If I understand you correctly then yes. You edit your project file to include conditional MSBUILD statements for the references/run times you need in which ever version.

I had a simillar answer here : Visual Studio loading the right (x86 or x64) dll!

Thought that in particular used the Build Platform/Target as the variable. I assume that you're using different Targets for setting the compilation conditions?

Community
  • 1
  • 1
Preet Sangha
  • 64,563
  • 18
  • 145
  • 216
  • Let me see if I get this straight: what I am supposed to do is to add a conditional to *Core* (and not App) that, based on something (say, a custom Target), will link against one version or another of "MyPortable"? Is that it? (btw, I edited my question to show that I have a reference to Core.csproj, and not Core.dll) – Rafael Steil May 08 '13 at 00:37
  • Sort of. ISTM that if you have a project reference then if you have the appropriate build targets the referencing should just work. – Preet Sangha May 08 '13 at 01:32
  • OK, great.. I got it working with some conditionals like you said. Looks like in the end I'll have a lot of these (one for each target platform), but at least it works! – Rafael Steil May 08 '13 at 16:14
0

You can control assembly binding from the config file, although I'm not sure that this is exactly what you are looking for.

Essentially you can tell your application to bind to a specific assembly:

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <dependentAssembly>
            <assemblyIdentity name="myAssembly"
                              publicKeyToken="32ab4ba45e0a69a1"
                              culture="neutral" />
            <bindingRedirect oldVersion="1.0.0.0"
                             newVersion="2.0.0.0"/>
         </dependentAssembly>
      </assemblyBinding>
   </runtime>
</configuration>

I took the above example from the MSDN documentation located here:

http://msdn.microsoft.com/en-us/library/2fc472t2.aspx

Hope that helps,

Chris

Chris Keller
  • 235
  • 3
  • 9