Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / CLR / October 2003

Tip: Looking for answers? Try searching our database.

How to add an assembly reference using CodeDOM?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mountain Bikn' Guy - 21 Oct 2003 17:49 GMT
This code (adapted from the examples in the docs) doesn't make complete
sense to me. I have it working, but I'm wondering why I need to declare an
assembly reference in 2 places. TIA.
Dave

CodeCompileUnit compileUnit = new CodeCompileUnit();
CodeNamespace myNamespace = new CodeNamespace("MyNamespace");
compileUnit.Namespaces.Add( myNamespace );
compileUnit.ReferencedAssemblies.Add(@"MyDLL.dll");//I declare an assembly
reference here first

myNamespace.Imports.Add( new CodeNamespaceImport("System") );
myNamespace.Imports.Add( new CodeNamespaceImport("MyOtherNamespace") );

[...]

ICodeCompiler compiler = provider.CreateCompiler();
CompilerParameters cp = new CompilerParameters(
new string[] {"System.dll",

"MyDLL.dll" //Now I still have to declare the assembly reference here too.
Why?

},

filepath.Substring(0, filepath.LastIndexOf(".") + 1)+"dll", false);
Kalpesh - 22 Oct 2003 10:53 GMT
I think this is similar to VS.NET IDE does internally

You must be knowing that
1) You can add references to assemblies that you wish to use by "Add
Reference"
2) You can use any of the classes of "References" inside your classes
using "using" statement

So, while compiling, you need to provide, which DLLs you want to add to
current assembly in compilation.

Since, there is a possibility that
Although you have added a ref. to an external assembly, but you dont
want to it to be included as a part of your assembly

Correct me, anyone, if I am conceptually wrong

Kalpesh

> This code (adapted from the examples in the docs) doesn't make complete
> sense to me. I have it working, but I'm wondering why I need to declare an
[quoted text clipped - 22 lines]
>
> filepath.Substring(0, filepath.LastIndexOf(".") + 1)+"dll", false);
Mountain Bikn' Guy - 22 Oct 2003 13:05 GMT
The "using" statements are taken care of by CodeNamespaceImport. However,
I'm speaking specifically about the need to declare assembly references
twice. I make one call with ReferencedAssemblies.Add. Then I am still
required (or I get errors) to define the assembly reference again as a
CompilerParameters parameter. That is the part that doesn't make sense to
me. It seems that ReferencedAssemblies.Add is not fully taking care of of
the task of defining a referenced assembly.
Dave

> I think this is similar to VS.NET IDE does internally
>
[quoted text clipped - 41 lines]
> >
> > filepath.Substring(0, filepath.LastIndexOf(".") + 1)+"dll", false);
Alan Pretre - 22 Oct 2003 20:38 GMT
> This code (adapted from the examples in the docs) doesn't make complete
> sense to me. I have it working, but I'm wondering why I need to declare an
> assembly reference in 2 places.
>
> CodeCompileUnit compileUnit = new CodeCompileUnit();

Hi.  I'm wondering why you are working with CodeCompileUnit at all?  Do you
have source code you are trying to compile or what?

If you have source code to work with then you would create the Compiler
object, add your CompilerParameters object, add your ReferencedAssemblies
and call CompileAssemblyFromSource() to compiler.  In this situation there
is only one time you need to add references.

-- Alan

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.