通过 VS 2015 RC 进行非 Azure 部署 [英] Non-Azure Deployment through VS 2015 RC

查看:43
本文介绍了通过 VS 2015 RC 进行非 Azure 部署的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在 VS 2015 Enterprise RC 上试用 ASP.NET 5 及其所有新功能.为了确保端到端的顺利部署,我然后尝试通过 VS 发布功能将应用程序部署到非 Azure 私有服务器.

I'm trying out ASP.NET 5 and all its new features on VS 2015 Enterprise RC. To ensure smooth end-to-end deployment, I then try to deploy the application to a non-Azure private server through VS Publish feature.

但是,我错过了一个非常重要的功能:发布到非 Azure 服务器的能力.

However, I'm missing out a very important feature: the ability to publish to a non-Azure server.

在早期版本的 Visual Studio(我使用的是 VS 2013)中,有自定义选项.

In earlier versions of Visual Studio (I'm using VS 2013), the Custom options is there.

我已尝试修改项目属性,但对如何将我的 ASP.NET 5 应用程序部署到自定义服务器一无所知.有任何想法吗?

I've tried tinkering with the Project Properties but nothing on how to deploy my ASP.NET 5 app to a custom server. Any ideas?

推荐答案

这是可行的(毕竟,发布到 Azure 网站也在内部使用 WebDeploy),但现在有点棘手,需要您进行一些调整.这是您可以执行的操作(对于 VS 2015 CTP6):

It's doable (after all, publishing to Azure websites also uses WebDeploy internally), but it's kinda tricky right now and requires you to tweak a few things. Here's what you can do (for VS 2015 CTP6):

Asp.net vnext 的目录结构与常规的 Asp.net 应用程序略有不同.有两个主要目录:approotwwwroot(如果您将应用程序部署到本地文件系统,您可以浏览它们).我们想部署这两个目录,但 IIS 网站路径必须指向 wwwroot 目录.这个问题似乎在 Web Deploy 3.6,但我只会手动处理.为了使其工作,您可以在 IIS 中创建两个网站/应用程序:

Asp.net vnext has slightly different directory structure than a regular Asp.net app. The are two main directories: approot and wwwroot (if you deploy the application to local filesystem, you can browse through them). We want to deploy both those dirs, but the IIS website path has to point to wwwroot dir. This problem seems to be addressed in Web Deploy 3.6, but i will just deal with it manually. In order for this to work, you can create two websites/applications in IIS:

  • 指向根应用程序目录并将仅用于部署的一个.我将其命名为 mysite-deploy.
  • 一个将用于实际托管我们网站并指向 wwwroot 目录的目录.我将其简单地命名为 mysite.
  • one that points to the root application dir and will be used just for deployment. I will name it mysite-deploy.
  • one that will be used to actually host our website and will point to wwwroot dir. I will name it simply mysite.
  1. 转到YourprojectDirPropertiesPublishProfiles
  2. 创建一个空的pubxml文件(即mysite.pubxml)

将以下内容粘贴到您的 pubxml 中:

Paste the following content into your pubxml:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <WebPublishMethod>MSDeploy</WebPublishMethod>
    <MSDeployPublishMethod>WMSVC</MSDeployPublishMethod>    
  </PropertyGroup>
</Project>

  1. 当您在 Visual Studio 中按发布"时,您应该会在列表中看到这个新配置文件.
  2. 像往常一样填写连接"选项卡(设置服务器、站点名称等).请记住将站点名称设置为部署站点 (mysite-deploy).
  3. 验证连接
  4. 试试预览选项卡 - 它很可能不起作用,但如果它起作用了 - 你就大功告成了.
  5. 点击发布
  6. Web Publish Activity 窗口中检查进度.
  1. When You press "Publish" in Visual Studio, you should see this new profile on the list.
  2. Fill out the Connection tab, as you would normally do (set Server, Site Name, etc.). Remember to set Site Name to the deployment site (mysite-deploy).
  3. Validate Connection
  4. Try the preview tab - it most probably wouldn't work, but in case it does - you're done.
  5. Click Publish
  6. Check progress in the Web Publish Activity window.

可能的错误

开箱即用,发布可能会失败.现在它变得棘手:)

Possible errors

Out of the box, the publish will probably fail. Now it gets tricky :)

起初,我得到的是这个错误:

At first, what I've got is this error:

C:Program Files (x86)MSBuildMicrosoftVisualStudiov14.0WebMicrosoft.AspNet.Publishing.targets(205,5): Error ERROR_FAILED_TO_DESERIALIZE: Web deployment task failed. ()
Publish failed to deploy.

让我们尝试解决这个问题.

Let's try to fix that.

再次打开Publish 窗口,并在Settings 选项卡上选中Publish using Powershell script 选项.再试一次.

Open the Publish window again, and check Publish using Powershell script option on the Settings tab. Try again.

如果您收到错误:ERROR_CERTIFICATE_VALIDATION_FAILED,这意味着您的计算机不信任目标计算机上IIS Management Service 的 SSL 证书.您可以尝试下载证书并将其添加到受信任的证书存储区,或者您可以完全禁用证书验证.

If you get an error: ERROR_CERTIFICATE_VALIDATION_FAILED, this means that the SSL certificate that IIS Management Service on your target machine is not trusted by your computer. You can try to download the certificate add it to trusted cert store, or you can disable certificate validation altogether.

在后一种情况下,您需要编辑位于 C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoft 的 publish-module.psm1Web ToolsPublishScripts1.0.0-prepublish-module.psm1.找到片段:

In the latter case, you need to edit publish-module.psm1 located at C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoftWeb ToolsPublishScripts1.0.0-prepublish-module.psm1. Find the fragment:

        # add excludes
        $sharedArgs.ExtraArgs += (GetInternal-ExcludeFilesArg -publishProperties $publishProperties)
        # add replacements
        $sharedArgs.ExtraArgs += (GetInternal-ReplacementsMSDeployArgs -publishProperties $publishProperties)

并添加:

$sharedArgs.ExtraArgs += '-allowUntrusted'

ERROR_COULD_NOT_CONNECT_TO_REMOTESVC

检查被调用的确切命令行 - 在 Web Publish Activity Window 中应该记录一行,从 Calling msdeploy with the command: 开始.查找 ComputerName=.如果它看起来像这样:ComputerName='https://https://myhost:8172/msdeploy.axd'/msdeploy.axd',那么你应该改变Server 发布配置文件中的字段Connectiontab to:myhost:8172.这是因为 powershell 脚本会自动添加https:///msdeploy.axd`.

ERROR_COULD_NOT_CONNECT_TO_REMOTESVC

Inspect the exact commandline that is getting invoked - in Web Publish Activity Window there should be a line logged, starting with Calling msdeploy with the command:. Look for ComputerName=. If it looks like this: ComputerName='https://https://myhost:8172/msdeploy.axd'/msdeploy.axd', then you should changeServerfield in Publish profileConnectiontab to:myhost:8172. That's because the powershell script automatically addshttps://and/msdeploy.axd`.

More Information: The provider 'contentPathLib' could not be found.  Learn more at: http://go.microsoft.com/fwlink/?LinkId=221672#ERROR_PROVIDER_NOT_FOUND.

再次转到C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoftWeb ToolsPublishScripts1.0.0-prepublish-module.psm1 并找到该行:

Go again to C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoftWeb ToolsPublishScripts1.0.0-prepublish-module.psm1 and find the line:

$publishArgs += '-enableLink:contentLibExtension'

这似乎是 Web Deploy 3.6 的一个特性,不过好像服务器端也得支持.要禁用它,只需注释掉这一行.警告:此更改可能会影响到 Azure 网站的 Powershell 部署.

This seems to be a feature of Web Deploy 3.6, but it seems that the server side has to support it also. To disable it, just comment out this line. Warning: This change may impact powershell deployment to Azure websites.

现在您的网站正在部署,还有一件事.我们想部署approotwwwroot 目录,而只部署wwwroot 目录的内容.为了解决这个问题,我们需要再次编辑 C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoftWeb ToolsPublishScripts1.0.0-prepublish-模块.psm1.

Now that your site is being deployed, there is one more thing. We wanted to deploy approot and wwwroot directory, and instead only the content of the wwwroot directory is deployed. To fix that, we need to once again edit C:Program Files (x86)Microsoft Visual Studio 14.0Common7IDEExtensionsMicrosoftWeb ToolsPublishScripts1.0.0-prepublish-module.psm1.

找到说:

$webrootOutputFolder = (get-item (Join-Path $packOutput $webroot)).FullName

然后,添加一个新行:

$webrootOutputFolder = $webrootOutputFolder | split-path -parent

这会将发布的文件夹设置为 wwwroot 的父文件夹,这正是我们所需要的.在再次发布之前,您可能需要清除您网站在服务器上的目录 - 现在发布的目录结构会有所不同.

This will set the published folder to the parent of wwwroot, which is exactly what we need. Before publishing again, you may want to clear your site's directory on the server - the published directory structure will be different now.

此时,站点应该已部署并在服务器上可用.在服务器端,您应该看到两个目录:approotwwwroot 以及一些脚本文件.

At this point, the site should be deployed and available on the server. On the server side, you should see two directories: approot and wwwroot and maybe some script files.

您必须自己调试任何服务器端错误.

Any server side errors you will have to debug yourself.

这篇关于通过 VS 2015 RC 进行非 Azure 部署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆