mvc razor_BIN将装有Razor的ASP.NET MVC 3部署到未安装MVC的Windows Server

mvc razor

mvc razor

If someone says "just bin Deploy it" they mean "deploy the application with the dependencies copied into the application's /bin folder, rather than running an MSI that installs the dependencies into the Global Assembly Cache (GAC)."

如果有人说“只是bin部署它”,它们的意思是“将依赖项复制到应用程序的/ bin文件夹中,而不是运行将依赖项安装到全局程序集缓存(GAC)中的MSI来部署应用程序。”

You may not have administrative control over your Web Server and your host may not want you running installers when new stuff like ASP.NET MVC 3 and Razor comes out. You'll want to "bin deploy" these new technologies.

当出现诸如ASP.NET MVC 3和Razor之类的新东西时,您可能没有对Web服务器的管理控制,并且主机可能不希望您运行安装程序。 您将要“分批部署”这些新技术。

Here's two ways. The simple way and The Awesome Way.

这有两种方法。 简单方式和超赞方式。

使用Razor进行BIN手动部署ASP.NET MVC 3的方法 (The Manual Way to BIN Deploy ASP.NET MVC 3 with Razor)

On your development machine that has ASP.NET MVC 3 installed you have a C:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3 folder and a C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages folder. In those folders are "Assemblies" folders.

在安装了ASP.NET MVC 3的开发计算机上,您有一个C:\ Program Files \ Microsoft ASP.NET \ ASP.NET MVC 3文件夹和一个C:\ Program Files(x86)\ Microsoft ASP.NET \ ASP。 NET Web Pages文件夹。 在这些文件夹中是“程序集”文件夹。

ASP.NET MVC itself references these additional assemblies.

ASP.NET MVC本身引用了这些附加程序集。

  • System.Web.Mvc (well, we ARE this assembly, actually)

    System.Web.Mvc(嗯,实际上我们是这个程序集)
  • Microsoft.Web.Infrastructure

    Microsoft.Web.Infrastructure
  • System.Web.Razor

    System.Web.Razor
  • System.Web.WebPages

    System.Web.WebPages
  • System.Web.WebPages.Razor

    System.Web.WebPages.Razor

And the default Web.config for projects also expects:

项目的默认Web.config也期望:

  • System.Web.Helpers

    System.Web.Helpers

After you deploy your ASP.NET MVC 3 Razor application, you'll need to manually copy these five assemblies to the \bin folder of your deployed application.

部署ASP.NET MVC 3 Razor应用程序后,需要将这五个程序集手动复制到已部署的应用程序的\ bin文件夹中。

NOTE: It's possible to just reference these assemblies directly from your application, then click properties on each one and set copyLocal=true. Then they'd get automatically copied to the bin folder. However, I have a problem with that philosophically. Your app doesn't need a reference to these assemblies. It's assemblies your app depends on. A depends on B that depends on C. Why should A manually set a dependency on C just to get better deployment? More on this, well, now.

注意:可以直接从您的应用程序直接引用这些程序集,然后单击每个程序集上的属性并设置copyLocal = true。 然后,它们会自动复制到bin文件夹中。 但是,从哲学上讲,我对此有疑问。 您的应用无需引用这些程序集。 它是您的应用程序所依赖的程序集。 A依赖于B,而B依赖于C。为什么A应当手动设置对C的依赖关系以更好地进行部署? 好吧,现在。

Now, you likely remember that "If you're using XCOPY for deployment, you're doing it wrong" so you're likely wondering how to make this deployment process less manual and more awesome.

现在,您可能还记得“如果您使用XCOPY进行部署,那么您做错了”,因此您可能想知道如何使此部署过程的手动性降低,变得更加出色。

Alpha-Geek炫耀的花式长裤采用面向未来的BIN方式与Razor一起部署ASP.NET MVC 3 (The Alpha-Geek Show-Off Fancy-Pants Future-Proofed Way to BIN Deploy ASP.NET MVC 3 with Razor)

I created a custom Windows 7 Virtual Machine that had only IIS7 and .NET 4 installed, plus Web Deploy, and nothing else in order to test this scenario. This machine has never seen ASP.NET MVC 3 or Razor and we're not installing anything on it. It's our pretend "shared host."

我创建了一个自定义的Windows 7虚拟机,该虚拟机仅安装了IIS7和.NET 4,还安装了Web Deploy ,而没有其他东西可以测试这种情况。 该机器从未见过ASP.NET MVC 3或Razor,并且我们没有在其上安装任何东西。 这是我们假装的“共享主机”。

In my ASP.NET MVC Application, I'm going to create a folder called "_bin_deployableAssemblies." Yes, that's a underscore in the front. IIS will not serve from folders whose first character is an underscore. You can thanks FrontPage for that feature. In fact, this guarantees that even if you accidentally copy this folder up (don't) it won't be served. Apparently I got bad info on this from the IIS team. I'm looking into this statement as it's incorrect.

在我的ASP.NET MVC应用程序中,我将创建一个名为“ _bin_deployableAssemblies”的文件夹。 是的,这是前面的下划线。 IIS不会从第一个字符是下划线的文件夹中提供服务。 您可以感谢FrontPage的功能。 实际上,这保证了即使您不小心将文件夹复制(不复制)也不会得到提供。 显然我从IIS团队那里得到了不好的信息。 我正在调查此声明,因为它是不正确的。

  • Create a _bin_deployableAssemblies folder.

    创建一个_bin_deployableAssemblies文件夹。
  • Copy the assemblies we want bin deployed into this _bin_deployableAssemblies folder.

    将我们要bin部署的程序集复制到此_bin_deployableAssemblies文件夹中。
  • Select them all, right click and hit properties. Set their Build Action to "None."

    全部选中它们,右键单击并单击属性。 将其构建操作设置为“无”。
  • You are expected to check these into source control as well.

    您也应该将它们检入源代码管理中。

Here's my Solution so far:

到目前为止,这是我的解决方案:

Here comes the secret awesome sauce.

这是秘密的真棒酱。

NOTE: You're reading this on some random dude's blog, so lower your expectation of support now. No, lower. Bit lower. There. Yes, that's zero support. If this accidentally formats your harddrive or deletes your source code, kick yourself hard so you'll wake up to the previous level of Inception, specifically the one where the skinny kid from Third Rock From The Sun is walking on the ceiling. Be careful. Make backups.

注意:您正在某个随机花花公子的博客上阅读此书,因此,现在降低对支持的期望。 不,更低降低一点。 那里。 是的,那是零支持。 如果这不小心格式化了您的硬盘驱动器或删除了源代码,请用力踢一下,以使您醒来之前的“盗梦空间”,特别是“太阳第三岩石”的瘦小孩子正走在天花板上的那一步。 小心。 进行备份。

Get ready, because we are going into the belly of the beast. This is for VS2010, to be clear. Also, your Program Files folder will vary depending on your x86/x64 version of Windows.

准备好,因为我们要进入野兽的腹部。 显然,这是针对VS2010的。 另外,您的Program Files文件夹将根据Windows的x86 / x64版本而有所不同。

  • Go into C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications and make a copy of this folder. Put it somewhere safe.

    进入C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ WebApplications并制作此文件夹的副本。 把它放在安全的地方。

  • Go  into C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web and make a copy of this folder. Put it somewhere safe.

    进入C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web并制作此文件夹的副本。 把它放在安全的地方。

  • Download this file and unzip it somewhere: FancyAndTotallyUnsupportedMSBuildFilesForBinDeployableAssemblies.zip

    下载此文件并将其解压缩到以下位置: FancyAndTotallyUnsupportedMSBuildFilesForBinDeployableAssemblies.zip

  • Inside is:

    里面是:

    • "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets"

      “ C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ WebApplications \ Microsoft.WebApplication.targets”

    • "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v10.0\Web\Microsoft.Web.Publishing.OnlyFilesToRunTheApp.targets"

      “ C:\ Program Files(x86)\ MSBuild \ Microsoft \ VisualStudio \ v10.0 \ Web \ Microsoft.Web.Publishing.OnlyFilesToRunTheApp.targets

  • Copy these new files OVER your existing ones (remember, the ones you backed up?)

    将这些新文件复制到现有文件上(还记得您备份的文件吗?)

Now when you build your Web Application, all the files that are in _bin_deployableAssemblies will automatically get copied into your /bin folder.

现在,当您构建Web应用程序时,_bin_deployableAssemblies中的所有文件都将自动复制到/ bin文件夹中。

This is better than a simple Post Build Step Batch File because it works specifically with publishing. Now, you can right click on your Web Project and "Publish..." an the bin folder contain your project's build output PLUS the _bin_deployableAssemblies folder.

这比简单的构建后步骤批处理文件要好,因为它特别适用于发布。 现在,您可以右键单击Web项目,然后在“发布...”的bin文件夹中包含项目的构建输出以及_bin_deployableAssemblies文件夹。

Build Deployment Package

I could publish directly to my Shared Host, or I can Build Deployment Package and get a ZIP file with all the things my app needs.

我可以直接发布到共享主机,也可以构建部署包并获取包含我的应用所需的所有内容的ZIP文件。

For me, as I have a VM (remember that I put Web Deploy on it?) and from IIS Manager just "Import Application." Some hosters have a control panel for this, but you'll likely use Web Deploy or Publish via FTP.

对我来说,因为我有一个VM(还记得我在上面放了Web Deploy吗?),而从IIS管理器中只是“导入应用程序”。 一些主机托管商为此提供了一个控制面板,但是您可能会使用Web Deploy或通过FTP发布。

This is a nice, clean, self-contained way to bin deploy an ASP.NET MVC 3 application with Razor views to a host that doesn't have any of these bits installed.

这是一种将带有Razor视图的ASP.NET MVC 3应用程序bin部署到未安装这些位的主机的一种很好,干净,独立的方法。

INTERESTING NOTE: In a "future update to Visual Studio 2010" (that's marketing code for SP1, which I'm not allowed to say) this feature will be built in. Because with this hack we've only messed with our built-in build targets, those files we've modified will be torched (replaced) with the new Visual Studio updated files, effectively undoing what we've done here. It's a "future-proofed hack."

有趣的注意:在“ Visual Studio 2010的未来更新”(这是SP1的市场营销代码,我不能说)中,将内置此功能。因为使用此hack,我们只是搞砸了内置程序构建目标时,我们修改过的文件将被新的Visual Studio更新文件删除(替换),从而有效地撤消了我们在此处所做的工作。 这是“面向未来的hack”。

Enjoy!

请享用!

翻译自: https://www.hanselman.com/blog/bin-deploying-aspnet-mvc-3-with-razor-to-a-windows-server-without-mvc-installed

mvc razor

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值