Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mono XBuild publish MVC site

Tags:

c#

mono

xbuild

I've got Monoserve and Nginx running perfectly in Ubuntu however I still have to publish the website locally on a Windows box using MSBuild and then copy the files over.

Preferably I'd like to have a Linux CI server that does this instead using XBuild however I can only get it to build the project into .dlls, how do I publish and deploy it with js, css, views, etc?

like image 463
Dharun Avatar asked Jan 12 '13 18:01

Dharun


1 Answers

Typically the "build dlls" part is the hardest part. If you've got that solved, you're 80% there. The other half is publishing content. In it's most elementary aspect, you're copying a portion of the files from the source dir to the website folder. MSDeploy is Microsoft's answer to it, and it's waaaaaay too complex. I built an NAnt task that does this, though that also doesn't apply to your specific scenario. However, the general methodology can:

  1. Crawl the sln file looking for web projects. What makes a web project? Technically guids in the csproj file or project type ids in the sln file. I cheated and defined it as "the target folder includes a web.config file". If you've only got one website project in your solution, you can skip this step, and just hard-code the .csproj file.

  2. Crawl the csproj file looking for <Content Include="some\file.ext" /> nodes. XPath could do this, Linq to XML could do it too. This gives you all the .aspx, .cshtml, .js, .css, .png, .config, etc, etc, while carefully leaving behind all the .cs files. You'll need to prefix the path to the .csproj file to get the true origin file location, and you want to ensure you preserve the folder structure in the destination location. But this is trivial in comparison to harvesting the file list.

  3. Now that you've got the file list, loop through it copying from the source folder to the destination folder. (You probably want to either empty the destination folder first or afterwards prune extra files from previous deployments. I find the former easier.) The only thing the csproj file crawl didn't give you was the bin folder content, but that's cake: copy all the contents of the bin folder. :D (There's a healthy debate about whether to copy .pdb files, but I say yes.)

Form a script to do the above 3 steps, then call it either from an XBuild task or call both XBuild and this script from the CI process. Poof. You've got a deploy target. Happy coding!

like image 107
robrich Avatar answered Nov 18 '22 12:11

robrich