Doug
Doug

Reputation: 35186

How do you build a mono mvc application on linux?

This is, as I understand it, the absolutely minimal MVC application its possible to have:

using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
public class HomeController : Controller {
  public string Index() {
    return "Hello World";
  }
}

My question is, without visual studio, or mono develop, how do you build this application on linux?

I personally, am running ubuntu; I expected to be able to do this via:

gmcs hello.cs

But that gives the error:

The type or namespace name `Mvc' does not exist in the namespace `System.Web'. Are you missing an assembly reference?

What? How do I get this required assembly? How do I depend on it?

I've been looking for an answer to this all day and I've seen solutions to this question that fall into four broad categories:

1) Put system.web.mvc.dll in a 'bin' folder and build it.

That didn't seem to do anything.

2) Compile the magical .sln file that visual studio created with xbuild.

I don't have one of those, or a copy of visual studio.

3) You don't need to compile web apps you just set the server up and it works.

No idea. I tried using xsp2 and creating a web.config is it just 404'd on localhost. I think this is just incorrect.

4) You need to compile mono from source for this to work.

I'm running 2.4 which is the std. ubuntu package; from the comments I've seen this should be sufficient?

So, how do you actually do this?

--

None of the solutions below (as of writing) actually had a final answer for this, but I've accepted one of them that pointed me in the correct direction.

To build the minimal MVC application (above) on ubuntu, I had to do the following:

apt-get install mono-2.0-devel
gmcs /out:bin/out.dll /target:module /reference:/usr/lib/mono/2.0/System.Web.Mvc.dll hello.cs

:D

Upvotes: 2

Views: 1529

Answers (1)

IanNorton
IanNorton

Reputation: 7282

In your example above you do not tell the compiler about any other library references you require. Thats why it fails with the message about missing references.

You tell gmcs and other compilers about other references with the following syntax:

$ gmcs /reference:path/to/my/assembly.dll /target:library path/to/my/csharp.cs

If you write your application in monodevelop or visual studio you can still build the solution without needing to load it up. You can do this using msbuild (on windows).

On linux you get a choice of using xbuild or mdtool. You will usually have mdtool if you also have monodevelop installed. xbuild is the mono equivalent of msbuild and will work just the same for most projects.

Monodevelop has the added advantage that you can get it to generate Makefiles so that your solution can be built in a more linux/unix way by running autotools and gnu make.

To tackle the problem in the last way you choose 'enable makefile integration for this project' when looking at the project properties in monodevelop. You will want to do this for all projects in your solution that you need.

Upvotes: 1

Related Questions