简体   繁体   English

Mono XBuild发布MVC网站

[英]Mono XBuild publish MVC site

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. 我已经在Ubuntu中运行了Monoserve和Nginx,但是我仍然需要使用MSBuild在Windows机器上本地发布网站,然后复制文件。

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? 我希望有一个Linux CI服务器,而不是使用XBuild,但我只能将它构建到.dll中,如何使用js,css,views等发布和部署它?

Typically the "build dlls" part is the hardest part. 通常,“构建dll”部分是最难的部分。 If you've got that solved, you're 80% there. 如果你已经解决了,那你就80%了。 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. MSDeploy是微软对它的回答,它太复杂了。 I built an NAnt task that does this, though that also doesn't apply to your specific scenario. 我构建了一个执行此操作的NAnt任务,但这也不适用于您的特定方案。 However, the general methodology can: 但是,一般方法可以:

  1. Crawl the sln file looking for web projects. 抓取sln文件寻找Web项目。 What makes a web project? 什么是网络项目? Technically guids in the csproj file or project type ids in the sln file. 技术上在csproj文件中的guids或sln文件中的项目类型id。 I cheated and defined it as "the target folder includes a web.config file". 我作弊并将其定义为“目标文件夹包含web.config文件”。 If you've only got one website project in your solution, you can skip this step, and just hard-code the .csproj file. 如果您的解决方案中只有一个网站项目,则可以跳过此步骤,只需对.csproj文件进行硬编码即可。

  2. Crawl the csproj file looking for <Content Include="some\\file.ext" /> nodes. 抓取csproj文件,查找<Content Include="some\\file.ext" />节点。 XPath could do this, Linq to XML could do it too. XPath可以做到这一点,Linq to XML也可以做到这一点。 This gives you all the .aspx, .cshtml, .js, .css, .png, .config, etc, etc, while carefully leaving behind all the .cs files. 这会给你所有.aspx,.cshtml,.js,.css,.png,.config等等,同时小心地留下所有的.cs文件。 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. 您需要在.csproj文件的路径前添加前缀以获取真正的原始文件位置,并且您希望确保在目标位置保留文件夹结构。 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. (您可能希望首先清空目标文件夹,或者之后从以前的部署中删除额外的文件。我发现前者更容易。)csproj文件爬网唯一没有给你的是bin文件夹内容,但那是蛋糕:copy bin文件夹的所有内容。 :D (There's a healthy debate about whether to copy .pdb files, but I say yes.) :D(关于是否复制.pdb文件有一个健康的争论,但我说是的。)

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. 形成一个脚本来执行上述3个步骤,然后从XBuild任务中调用它,或者从CI过程调用XBuild和此脚本。 Poof. 噗。 You've got a deploy target. 你有一个部署目标。 Happy coding! 快乐的编码!

Preferably I'd like to have a Linux CI server that does this instead using XBuild The good news is that you CAN do this with a workaround I found in this article. 我希望有一个Linux CI服务器来代替使用XBuild 。好消息是你可以通过我在本文中找到的解决方法来实现这一点 Here is an excerpt and the workaround link from the above article: 以下是上述文章的摘录和解决方法链接:

The build server does not have Microsoft MVC (any version) installed. 构建服务器未安装Microsoft MVC(任何版本)。 However, this is very easy to work around-Microsoft MVC is available on NuGet at http://nuget.org/packages/Microsoft.AspNet.Mvc if you need to install an older version, click on the older version at the bottom of the page and you'll reach instructions on how to install that version of the framework. 但是,这很容易解决 - 如果您需要安装旧版本,可以在NuGet上的http://nuget.org/packages/Microsoft.AspNet.Mvc上找到Microsoft MVC,点击底部的旧版本该页面,您将获得有关如何安装该版本框架的说明。

Hope this make it easy for you! 希望这能让你轻松!

@DHarun 's idea works great! @DHarun的想法很棒! I just wrote a small script based on @Dharun 's idea, hope it may help others. 我刚刚根据@Dharun的想法写了一个小脚本,希望它可以帮助别人。 https://github.com/z-ji/MonoWebPublisher https://github.com/z-ji/MonoWebPublisher

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM