你如何在Linux上构建单声道mvc应用程序?

时间:2011-05-05 12:54:25

标签: .net model-view-controller mono

据我所知,这是一个绝对最小的MVC应用程序:

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

我的问题是,如果没有visual studio或mono develop,你如何在linux上构建这个应用程序?

我个人,正在运行ubuntu;我希望能够通过以下方式做到这一点:

gmcs hello.cs

但是这给出了错误:

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

什么?如何获得所需的组装?我如何依赖它?

我一直在寻找这个问题的答案,我已经看到这个问题的解决方案分为四大类:

1)将system.web.mvc.dll放在'bin'文件夹中并构建它。

这似乎没有做任何事情。

2)编译visual studio使用xbuild创建的神奇的.sln文件。

我没有其中一个,或视觉工作室的副本。

3)您不需要编译只需设置服务器的Web应用程序即可。

不知道。我尝试使用xsp2并创建一个web.config,它只是在localhost上404。我认为这是不正确的。

4)你需要从源代码编译单声道才能工作。

我正在运行2.4这是标准。 ubuntu包;从我看过的评论中,这应该足够了吗?

那么,你怎么做呢?

-

下面的任何解决方案(截至撰写时)都没有为此做出最终答案,但我接受了其中一个指向正确方向的方法。

要在ubuntu上构建最小的MVC应用程序(上面),我必须执行以下操作:

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

1 个答案:

答案 0 :(得分:1)

在上面的示例中,您不会告诉编译器您需要的任何其他库引用。这就是为什么它失败了关于缺少参考的消息。

使用以下语法告诉gmcs和其他编译器有关其他引用的信息:

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

如果您在monodevelop或visual studio中编写应用程序,您仍然可以构建解决方案而无需加载它。您可以使用msbuild(在Windows上)执行此操作。

在linux上,您可以选择使用xbuild或mdtool。如果你也安装了monodevelop,你通常会有mdtool。 xbuild是msbuild的单声道等价物,对大多数项目来说都是一样的。

Monodevelop具有额外的优势,您可以通过运行autotools和gnu make来生成Makefile,以便通过更多linux / unix方式构建解决方案。

在monodevelop中查看项目属性时,以最后一种方式选择“为此项目启用makefile集成”来解决问题。您需要为解决方案中所需的所有项目执行此操作。

相关问题