Search code examples
.netmonodevelopxamarin-studio

How do I add a reference when building a single file in MonoDevelop/Xamarin Studio?


I am working on a single file (not a project or solution) with Xamarin Studio, but I can't build it because I can't reference some DLLs in the same directory. Without making a new project (as this is overkill), how do I tell the IDE to reference those libraries, explicitly or automatically, when compiling this single file?


Solution

  • I don't really see how a project is overkill for this - it's a single XML file that would reference the file and assemblies in the directory and provide compiler options. Without a solution or multiple build configurations, you can slim it down to probably 10-20 lines, and would simplify building cross-platform, similar to a Makefile.

    However, this is still possible to do. On the command line you can reference assemblies with the /r or /reference options. For example:

    mcs /reference:System.Drawing.dll Main.cs
    

    would reference System.Drawing. You may also need to specify the current directory as one where assemblies exist. This might just work, but in case it doesn't, it would be the /lib or -L options. More details on the mcs man page.

    I don't believe MonoDevelop/Xamarin Studio has any built-in way to include those compiler options from within the source file, but it does have the ability to invoke Makefiles, so throw your version of the mcs command into a Makefile in the same directory and you should be able to invoke it from MonoDevelop/Xamarin Studio.