1

I am using a batch file with the following commands to successfully compile a C# code on the fly, run the resulting exe and destry the exe.

start /wait C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe /out:PostillionOutgoing.exe PostillionOutgoing.cs  /reference:AlexPilotti.FTPS.Client.dll
call  SetupCI.bat
start /wait PostillionOutgoing.exe
del PostillionOutgoing.exe

It works exactly the way I wanted. File AlexPilotti.FTPS.Client.dll is present in the same folder as the .cs files are.

The assembly AlexPilotti.FTPS.Client.dll is also needed by a lot of other similar applications. My question is that is there any centralised place where I can keep this DLL so that all the above batch scripts will find it ? By this way I wont have to keep a copy of this DLL in all the separate folders.

I dont want to place the DLL in GAC. I tried in system32 folder also but it didnt work.

Akshay J
  • 5,362
  • 13
  • 68
  • 105

2 Answers2

1

As per the documentation, there is no fixed location that the runtime uses when probing for assemblies (i.e. when it looks into directories because it hasn't been able to locate the assembly already).

However, if your assembly is strongly named then you can use a <codeBase> configuration element in your app.config to direct the runtime to any path of your choosing.

If your assembly isn't strongly named and you don't want to use app.config then unfortunately you are out of options.

Jon
  • 428,835
  • 81
  • 738
  • 806
1

You can use the /lib command line to specify search folders for references

see msdn docs here http://msdn.microsoft.com/en-us/library/vstudio/s5bac5fx.aspx

Dreamwalker
  • 3,032
  • 4
  • 30
  • 60
  • I tried the lib option and changed the first line to start /wait C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe /lib:C:\Windows\System32\ /out:PostillionOutgoing.exe PostillionOutgoing.cs /reference:AlexPilotti.FTPS.Client.dll, but still the same error, I have copied that DLL to specified folder though – Akshay J Feb 27 '13 at 13:35
  • I placed in some directory other than System32 and it worked. – Akshay J Feb 27 '13 at 13:47
  • There might be a permission issue using system32 can't say I know my self though. But I wouldn't want to use that folder anyway, for instance you may want to clear all dlls to ensure they are recreated. Glad to here its working – Dreamwalker Feb 27 '13 at 13:58
  • One more thing. Is thre any similar thing for runtime also? I mean just for compilation /lib would work. But at run time, I guess it will expect the DLL to be in same folder as the exe. Is there similar thing like /lib for runtime also. So that at runtime, instead of looking for the DLL in the same folder (or GAC) it would look for the DLL in the same folder where the DLL was placed(during compilation) ? – Akshay J Feb 27 '13 at 14:08
  • I actually answered this question originally with that info :) see this related question http://stackoverflow.com/questions/1373100/how-to-add-folder-to-assembly-search-path-at-runtime-in-net – Dreamwalker Feb 27 '13 at 14:10
  • I could not find any answer by you (Zonder) – Akshay J Feb 28 '13 at 05:27
  • sorry I wasn't clear in my post I meant I answered this question with the info on adding search paths at runtime. The post I linked to has code in the first answer, the routine is the same as the second answer just clearer to understand what is going on. – Dreamwalker Feb 28 '13 at 07:39