csc.exe reference external .dll file

前端 未结 3 614
逝去的感伤
逝去的感伤 2020-12-01 21:59

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

I tried to compile my program in two different ways:

1)

相关标签:
3条回答
  • 2020-12-01 22:17

    You can add these using the /lib and /reference command-line switches while compiling.

    http://msdn.microsoft.com/en-us/library/s5bac5fx.aspx

    But (Quote from the article)

    An alternative to using /lib is to copy into the working directory any required assemblies; this will allow you to simply pass the assembly name to /reference. You can then delete the assemblies from the working directory. Since the path to the dependent assembly is not specified in the assembly manifest, the application can be started on the target computer and will find and use the assembly in the global assembly cache.

    Because the compiler can reference the assembly does not imply the common language runtime will be able to find and load the assembly at runtime. See How the Runtime Locates Assemblies for details on how the runtime searches for referenced assemblies.

    so Jon Skeet's answer is better. (I'm just adding this to provide more info than I could in a comment, not as an answer. Jon's answer is the best IMO)

    0 讨论(0)
  • 2020-12-01 22:28

    You can create symlinks to the assemblies in your libraries folder so you would only need to keep them updated in one location.

    0 讨论(0)
  • 2020-12-01 22:35

    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.

    0 讨论(0)
提交回复
热议问题