Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
717 views
in Technique[技术] by (71.8m points)

c# - csc.exe reference external .dll file

I am trying to make a simple c# program using Growl C# API.

I tried to compile my program in two different ways:

1) I kept my .dll file in the same directory as my .cs file. Than I ran

csc /r:Growl.Connector.dll,Growl.CoreLibrary.dll /out:test.exe *.cs

It compiled fine and also ran fine.

2) Now I have created a directory inside my current working directory named growl and kept all my .dll references there.

Now when I try to compile it using the below command

csc /r:"D:ModifiedGrowl_NET_Connector_SDKlibrariesgrowlGrowl.Connector.dll","D:
ModifiedGrowl_NET_Connector_SDKlibrariesgrowlGrowl.CoreLibrary.dll" /out:test.exe *.cs

It compiled fine but when I tried to run it the below mentioned exception occurred.

Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'Growl.Connector, Version=2.0.0.0, Culture=n
eutral, PublicKeyToken=980c2339411be384' or one of its dependencies. The system cannot find the file specified.
 at GrowlNotification.Program.Main(String[] args)

So, my question is what is the correct way to reference .dll file in csc when files are in an external folder.

Here is the directory structure for 2nd case.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

So, my question is what is the correct way to reference .dll file in csc when files are in an external folder.

You're already referencing them at build time. You just need to make them available at execution time too, but copying them into the same directory as the executable, when you want to run it.

You could also investigate using the Global Assembly Cache if these are signed assemblies, but personally I'd stick with just keeping the executable with the libraries on which it depends.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...