I'm very new to C# and have more knowledge in the field of C++ and Java. When compiling a C++ or Java project, I am used to that compilation is performed for each source file on its own. In C++, and additional step to link all the object files into one library/exe/dll is taken afterwards.
I see several advantages in this method, but I can not find a way to realize it in C# using the mono dmcs
compiler. Assume I have two files each with a single class.
OptionsSet.cs
interface OptionsSet {
//
}
DefaultOptionsSet.cs
class DefaultOptionsSet : OptionsSet {
//
}
I can successfully compile this into a library by invoking
dmcs mylib/OptionsSet.cs mylib/DefaultOptionsSet.cs -target:library -out:mylib.dll
But I do not want to recompile all source files when I changed a single file! Doing the following:
dmcs mylib/DefaultOptionsSet.cs -target:library -out:mylib/DefaultOptionsSet.dll
yields
mylib\DefaultOptionsSet.cs(15,27): error CS0246: The type or namespace name `OptionsSet' could not be found. Are you missing an assembly reference?
Compilation failed: 1 error(s), 0 warnings
I know I can add assembly references with the -r
option, but what if the assembly reference was not yet compiled?
In Java, my Makefile would look like this:
SOURCE_DIRS = mylib
SOURCES = $(foreach dir,$(SOURCE_DIRS),$(wildcard $(dir)/*.java))
CLASSES = $(SOURCES:java=class)
compile: $(CLASSES)
mylib/%.class: mylib/%.java
javac $< -classpath .
But I can not directly translate this to build my C# library.