Using nmake

You can use nmake to automate many tasks that build assemblies and modules. Here’s an example that shows many of the previous command lines, in a cohesive manner. Particular nmake features to note are the use of the .SUFFIXES keyword to add a definition for the .cs file extension and the use of the response file with the C# compiler, for when more source-file names are being supplied that can be listed on the command line.

REF=/r:c.dll
DEBUG=/debug
.SUFFIXES: .exe .dll .cs
.cs.dll:
	csc /t:module $*.cs
.cs.exe:
	csc $(DEBUG) $(REF) @<<big.tmp
$*.cs $(SRCLIST)
<<
all : d.exe f.exe
d.exe : d.cs c.dll
c.dll : a.dll b.dll
	al /out:c.dll a.dll b.dll
b.dll : b.cs
a.dll : a.cs
key.snk :
	sn -k $*.snk
e.dll : a.dll b.dll key.snk
	al /out:$*.dll /keyfile:key.snk a.dll b.dll
	al /i:$*.dll
f.exe : f.cs e.dll
	csc $(DEBUG) /r:.\e.dll f.cs
clean:
	del a.dll b.dll c.dll d.exe /q

Get C# Essentials now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.