Reputation: 13367
I am new to Mono, just freshly installed and am trying to get the basic setup up.
Hello.cs:
using System;
using Customz;
public class Hello
{
public static int Main(string[] args)
{
Console.WriteLine( "Hello world! Customz.Beko.Wally = " + Beko.Wally() );
Console.ReadKey();
return 0;
}
}
Customz/Beko.cs:
namespace Customz
{
public class Beko
{
public static int Wally()
{
return 15;
}
}
}
Basicly, I have been working with C# previously in Unity3D's adaption of MonoDevelop and Visual Studio.
I remember, that upon compilation, all the classes / namespaces get auto referenced when they are requested. Plus, they are looked up no matter how deep they dwell within the project directory / subdirectories.
Compiling this with:
mcs "C:\Users\psycketom\Desktop\Mono-C#\test\Hello.cs"
Results in:
C:\Users\psycketom\Desktop\Mono-C#\test\Hello.cs(2,7): error CS0246: The type or namespace name `Customz' could not be found. Are you missing a using directive or an assembly reference?
Compilation failed: 1 error(s), 0 warnings
Well, I know that I am not missing a using
directive, but I have a feeling that I am missing an assembly reference.
How can I fix this and achieve the Visual Studio like behavior?
I managed to compile everything in a directory by issuing:
mcs -out:app.exe "C:\Users\psycketom\Desktop\Mono-C#\test\*.cs"
While it works, it does include only files within the folder, not taking into account any subfolders residing in the folder.
How do I make it select all the files, including those residing in subfolders? (I'm starting to think that I may need a bash script or something)
Upvotes: 0
Views: 1197
Reputation: 63875
You'll probably want to be using make, NAnt or some other build system rather than the raw command line. The problem is this:
Your project folder has a few files and few folders. So you have
When you use mcs -out:app.exe "C:\Users\psycketom\Desktop\Mono-C#\test\*.cs"
the command line shell (NOT the compiler) will expand the *
wildcard for you. So, it expands to
Most shells don't go recursive(maybe without a special directive?) because it's much more expensive and generally unexpected behavior.
If you're really determined to use the command line, you'll have to do something like this:
mcs -out:app.exe "C:\Users\psycketom\Desktop\Mono-C#\test*.cs" "C:\Users\psycketom\Desktop\Mono-C#\test\Biz*.cs"
Also, if you're that determined to use the command line, you'll probably want to give something like Cygwin a try. It's a million times easier to use than cmd.exe
(and it seems to work well with Mono)
One more idea that I've used in the past: You can also use something like MonoDevelop to manage a solution and project files, which basically will link everything up in your program and tell the compiler what needs to be included. Outside of that though, you can easily build from the command line by using the xbuild
tool and the solution file that MonoDevelop made
Upvotes: 1