[UPDATED] Since posting this I've updated it to include using MVC2.
I'm a long time C# developer on Windows but I was interested to see if it's possible to develop on a Mac using Mono. Here are my notes on the setup:
Prerequisites
I'm a long time C# developer on Windows but I was interested to see if it's possible to develop on a Mac using Mono. Here are my notes on the setup:
Prerequisites
- Mac 32 or 64 bit? http://support.apple.com/kb/HT3696
- Java SDK: included in Mac OsX
- Mono: http://www.go-mono.com/mono-downloads/download.html
- MonoDevelop (Xamarin studio): http://monodevelop.com/Download
- A development IDE: e.g. Mono Develop: http://monodevelop.com/Download
or Eclipse: http://www.eclipse.org/downloads/packages/eclipse-ide-java-ee-developers/indigor - Check MD5 checksums:
- Open Terminal: Applications, Utilities, Terminal
- Type: md5 downloads/eclipse[version and build name].tar.gz
- Install XCode (so you can compile mod mono): Either from your install disk or from http://developer.apple.com/xcode/ NB: To download you'll need Lion (10.7+) and to sign up as a developer first.
- Install the XCode developer tools:
In Terminal: xcode-select --install
Older versions: Open XCode then go to Preferences, Downloads, and install Command Line Tools.
Make a directory for your Mono projects
I'm going to use /Users/[username]/Mono/
- mkdir /Users/[username]/Mono
Also make a TestMono directory under this directory
mkdir /Users/[username]/Mono/TestMono
Create a Test Project
- Open MonoDevelop and create a new C# Web MVC2 project, I called it TestMono.
Note: The default location for projects is [user folder]/Projects which I found a bit generic so I changed it to [user folder]/Mono. - Run it to test (Alt, Command key and Enter). It should load http://127.0.0.1:8080/ and show an MVC generated page.
To run Your Application under Apache
For external testing e.g. from your mobile to the Mac you'll need Apache or equivalent:
Open Terminal and Switch to root
Activate in-built Apache Web server (and Mac firewall)Open Terminal and Switch to root
- Terminal.app
- sudo su -
UPDATE: see separate post
- If you are using Mountain Lion+ web sharing has been removed so activate apache via the command line:
- Start Apache: /usr/sbin/apachectl start
- Apple, System Preferences
- Sharing, tick Web Sharing
- Mac Firewall
Apple, System Preferences, Security, activate Firewall (ensure Web Sharing allowed). - Check it runs: http://localhost
Get Mod mono
The connector between Mono and your web server
- Download and compile it. In Terminal:
- Make directory for the files:
mkdir ~/modmono - Change to that directory:
cd ~/modmono - Make a link to the mono framework command:
sudo ln -s /Library/Frameworks/Mono.framework/Commands/pkg-config /usr/bin/pkg-config - Download the source:
curl -O http://download.mono-project.com/sources/mod_mono/mod_mono-3.8.tar.gz - Extract it:
tar xzf mod_mono-3.8.tar.gz - Change into that directory:
cd mod_mono-2.10 - Run the configure script:
./configure --prefix=/usr - Make the source:
make
sudo make install - Copy the conf file to the apache2 folder:
sudo cp /etc/apache2/mod_mono.conf /etc/apache2/other
- Make directory for the files:
- Edit /etc/apache2/httpd.conf to tie the two together
Copy the original:
cp /etc/apache2/httpd.conf /etc/apache2/httpd.conf.bak
Insert the reference to mod_mono.conf:
vi /etc/apache2/httpd.conf"
Press Shift G to go to the end, i to enter insert mode and paste in the following at the end of the file:
# mod_mono_configuration
Include /etc/apache2/mod_mono.conf
MonoServerPath /Library/Frameworks/Mono.framework/Versions/Current/bin/mod-mono-server4
AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd
MonoAutoApplication disabled
- In Terminal:
- vi /private/etc/apache2/other/mono.conf
- Press i to begin insert then paste (replace [username] with your username:
AddHandler mono .aspx .ascx .asax .ashx .config .cs .asmx .axd
MonoAutoApplication disabled
MonoServerPath /Library/Frameworks/Mono.framework/Commands/mod-mono-server4
Alias /testmono "/Users/[username]/Mono/TestMono/"
<Directory "/Users/[username]/Mono/TestMono/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
Alias /testmono2 "/Users/[username]/Mono/TestMono2/"<Directory "/Users/[username]/Mono/TestMono2/">
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
AddMonoApplications default "/testmono:/Users/[username]/Mono/TestMono/,/testmono2:/Users/[username]/Mono/TestMono2/"
<Location /testmono>
SetHandler mono
</Location>
<Location /testmono2>
SetHandler mono
</Location> - Press Esc, :wq Enter to escape insert mode, save the file (:w) and quit (:q)
- Create a test index.aspx
echo "<center>mod_mono is working:<%=
System.DateTime.Now.ToString()%></center>" > /Users/[username]/Mono/TestMono/index.aspx - Restart Apache: sudo /usr/sbin/apachectl restart
- Test it:http://localhost/testmono/
http://localhost/mvc2/
Thanks to Michael Buen:
http://www.ienablemuch.com/2010/10/aspnet-on-mac-os-x-snow-leopard-at-one.html
http://www.ienablemuch.com/2010/10/troubleshooting-aspnet-mvc-4-app-in.html
MVC3 with Razor in Xamarin Studio
Troubleshooting
http://www.ienablemuch.com/2010/10/aspnet-on-mac-os-x-snow-leopard-at-one.html
http://www.ienablemuch.com/2010/10/troubleshooting-aspnet-mvc-4-app-in.html
MVC3 with Razor in Xamarin Studio
- Create new MVC3 project
Notice broken references to System.Web.Helpers and System.Web.Webpages - Add Nuget:
- Xamarin Add in Manager
- Gallery tab, Repositoy, select Manage Repositories
- Add unofficial Nuget Add-in http://mrward.github.com/monodevelop-nuget-addin-repository/4.0/main.mrep
- Install the NugetPackage from the new repository: IDE extensions, NuGet
- Manage Project Nuget Packages
- Add Microsoft ASPNet Web Pages 2
Troubleshooting
- Apache logs: vi /var/log/apache2/error_log
- Mac Console: find using the search in top right: this will list all errors so look for those starting org.apache...
- Lion: after upgrading to Lion I found I had an error in Console:
org.apache.httpd: httpd: Syntax error on line 499 of /private/etc/apache2/httpd.conf: Syntax error on line 8 of /private/etc/apache2/other/mod_mono.conf: Cannot load /usr/libexec/apache2/mod_mono.so into server: dlopen(/usr/libexec/apache2/mod_mono.so, 10): image not found. This post on stackoverflow.com helped me fix it.
No comments:
Post a Comment