tags:

views:

257

answers:

2

I am defining some Expression variables in my app and need to have a reference to Microsoft.Scripting.Core. That assembly includes the same namespace as the System.Core assembly from the main .Net framework.

I want to use the defintions from the System.Core assembly as it's stable whereas the Microsoft.Scripting.Core is alpha.

How do I tell my app to preference the System.Linq.Expressions namespace in System.Core instead of Microsoft.Scripting.Core but still be able to keep the reference to it?

+1  A: 

If they are the same namespace but different assemblies, then you may need to look at "extern alias", but that gets very messy very quickly.

If they are different namespaces, then simply use different using directives; you can also use using aliasing. However, lambdas will always (AFAIK) use the original namespace.

Marc Gravell
Both assemblies are using the exact same namespace of System.Linq.Expressions unfortunately.
sipwiz
+1  A: 

As Marc says, it's not terribly nice - but extern aliases are the way to go.

In the "References" part of solution explorer, select the System.Core assembly, go to properties. Change the "Aliases" property to include "syscore", e.g.

Aliases: global,syscore

Then at the top of any file where you want to use System.Linq.Expressions, type:

extern alias syscore;
using syscore::System.Linq.Expressions;

It's ugly, but at least it's possible :)

As a caveat, I've seen some problems when it comes to extension methods and extern aliases, as described in this question.

Jon Skeet