This example is a little contrived but it demonstrates how this works:
A.cs:
namespace RefTest
{
public class ClassA
{
}
}
>csc /target:library A.cs
>csc /target:library /out:A2.dll A.cs
Now I have A.dll and A2.dll
If I want to compile the following with a reference to both A.dll and A2.dll:
Bad.cs:
using System;
namespace RefTest
{
public class Program
{
public static int Main(string[] args)
{
ClassA a = new ClassA();
Console.WriteLine("ClassA = " + a);
return 0;
}
}
}
>csc /target:exe /reference:A.dll /reference:A2.dll Bad.cs
I'll get the following compiler error:
error CS0433: The type 'RefTest.ClassA' exists in both 'e:\NameConflictRefTest\A.dll' and 'e:\NameConflictRefTest\A2.dll'
To fix this I need to do the following:
Good.cs:
extern alias A2;
using System;
namespace RefTest
{
public class Program
{
public static int Main(string[] args)
{
ClassA a = new ClassA();
A2::RefTest.ClassA a2 = new A2::RefTest.ClassA();
Console.WriteLine("ClassA = " + a);
Console.WriteLine("A2::RefTest.ClassA = " + a2);
return 0;
}
}
}
>csc /target:exe /reference:A.dll /reference:A2=A2.dll Good.cs
Now I have Good.exe which references both A.dll and A2.dll and uses the ClassA from each of these two assemblies.