none
Visual Studio 2010 Compile with /reference:ExternAlias1=MyAssembly.dll RRS feed

  • Question

  • About the extern alias feature:
     
    Two DLLs contain separate versions of the same component, and you use two /reference with alias options to compile the source file. The options look like this:
     
    /reference:ExternAlias1=1.dll and /reference:ExternAlias2=2.dll
     
    This sets up the external aliases "ExternAlias1" and "ExternAlias2" which you use in your program by means of an extern statement:
     
     extern alias ExternAlias1;
     extern alias ExternAlias2;
     // Using statements go here.

    Once this is done, you can refer to the grid control from 1.dll by prefixing the control name with ExternAlias1, like this:
     ExternAlias1::MyNamespace.MyClass
     
    In addition, you can refer to the grid control from 2.dll by prefixing the control name with ExternalAlias2, like this:
     ExternAlias2::MyNamespace.MyClass
     
    How do you do it with Visual Studio (2010), I don't want to use the command prompt?
     
    For Example, In my Visual Studio (2010) solution, I got 1 console application project "ConsoleApplication1", and 2 class libraries "ClassLibrary1" and "ClassLibrary2"
     
    Code Snippet:
     
    ClassLibrary1:
     
    using System;
     
    namespace MyNamespace
     {
         class MyClass
         {
             public MyClass()
             {
                 Console.WriteLine("Constructing from ClassLibrary1");
             }
         }
     }

    ClassLibrary2:
     
    using System;
     
    namespace MyNamespace
     {
         class MyClass
         {
             public MyClass()
             {
                 Console.WriteLine("Constructing from ClassLibrary2");
             }
         }
     }
     
    How to I compile the 2 class libraries "ClassLibrary1" and "ClassLibrary2" with extern alias using Visual Studio (2010) and without using command prompts?
     
    So that you can achieve the following for ConsoleApplication1:
     
    ConsoleApplication1:
     
    //Add references to "ClassLibrary1" and "ClassLibrary2"
     
    extern alias Assembly1;
     extern alias Assembly2;
     
    using System;
     
    namespace ConsoleApplication1
     {
         class Program
         {
             static void Main()
             {
                 Assembly::MyNamespace.MyClass MC = new Assembly::MyNamespace.MyClass();
                 Console.ReadKey();
             }
         }
     }
     
    Please help.
     
    Thanks

    • Moved by Bob Shen Wednesday, July 18, 2012 9:14 AM (From:Visual C# General)
    Tuesday, July 17, 2012 12:43 PM

Answers

  • Hi Recherche,

    Welcome to the MSDN Forum.

    Based on your description, it seems that you want to know how to add the two same name assembly in a project. If I am correct, please take a look at this blog: http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx 

    It provides very detailed steps to introduce this way.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by recherche Thursday, July 19, 2012 6:14 AM
    Wednesday, July 18, 2012 10:31 AM
    Moderator

All replies

  • Hi Recherche,

    Welcome to the MSDN Forum.

    Based on your description, it seems that you want to know how to add the two same name assembly in a project. If I am correct, please take a look at this blog: http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx 

    It provides very detailed steps to introduce this way.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by recherche Thursday, July 19, 2012 6:14 AM
    Wednesday, July 18, 2012 10:31 AM
    Moderator
  • Hi Recherche,

    Welcome to the MSDN Forum.

    Based on your description, it seems that you want to know how to add the two same name assembly in a project. If I am correct, please take a look at this blog: http://blogs.msdn.com/b/ansonh/archive/2006/09/27/774692.aspx 

    It provides very detailed steps to introduce this way.

    I hope this will be helpful.

    Best regards,


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

           You hit the nail on its head! Thanks Mike Feng for the answer.
    Thursday, July 19, 2012 6:15 AM