将 Visual Studio Web 应用程序部署到 IIS(甚至可能是 Azure 持续部署 Git)?

Deploy Visual Studio Web App to IIS (Maybe Even Azure Continuous Deployment Git)?

我正在尝试从 VS 2015 RC 部署我的 MVC 6 Web 应用程序。我正在使用 IIS 7.5。我浏览过其他用户关于类似部署的问题,但他们的解决方案对我没有用...

具体来说,我正在按照本指南进行操作(未成功):http://dotnetspeak.com/2015/03/publish-asp-net-v-next-to-iis

我实际上只是想发布默认的 .NET 5/MVC 6 Visual Studio Web 应用程序...下面是我尝试过的详细说明。不知道我做错了什么。我承认,我对 IIS 和 .NET 很生疏。所以请记住这一点!


Visual Studio 2015 年网络发布

作者告诉你:

Right click on Default Web Site and choose Add Application

所以我在 'Publish Web' 期间使用的值:

然后我看到:

Your application will be published to:

C:\inetpub\wwwroot\DerekFoulk.com

所以我点击了发布


添加到 IIS 7.5

在执行此操作之前,我注意到 IIS 中已经有一个条目与我的项目同名。这可能是因为我一直在使用默认 'Start Debugging - IIS Express' 按钮在浏览器中预览我的应用吗?

然后我打开 IIS 并右键单击 默认网站 并单击 添加应用程序 。我使用了以下配置:

然后我点击 测试设置 并收到以下错误消息:

There was an error while performing this operation.

Details:

Invalid application path

作者没有提到检查设置,即使我知道这意味着事情不会正常进行,我还是点击了 OK

最后,作者说到:

Go to security in windows explorer under TestApp folder. Add Authenticated Users group account and give it read and execute rights.

所以我右键单击目录 (C:\inetpub\wwwroot\DerekFoulk.com) 并转到 Properties > Security 和没有看到经过身份验证的用户组。但是,我确实看到 IIS_IUSRS 具有 Read & execute 权限。我认为这些是适当的权限,并继续尝试在浏览器中查看我的应用程序...

我导航到 http://localhost/DerekFoulk/。它在页面上显示以下错误:

<!DOCTYPE html>
<html>
    <head>
        <title>Could not load file or assembly 'dnx.clr.managed' or one of its dependencies. The system cannot find the file specified.</title>
        <meta name="viewport" content="width=device-width" />
        <style>
         body {font-family:"Verdana";font-weight:normal;font-size: .7em;color:black;} 
         p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px}
         b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px}
         H1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red }
         H2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon }
         pre {font-family:"Consolas","Lucida Console",Monospace;font-size:11pt;margin:0;padding:0.5em;line-height:14pt}
         .marker {font-weight: bold; color: black;text-decoration: none;}
         .version {color: gray;}
         .error {margin-bottom: 10px;}
         .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; }
         @media screen and (max-width: 639px) {
          pre { width: 440px; overflow: auto; white-space: pre-wrap; word-wrap: break-word; }
         }
         @media screen and (max-width: 479px) {
          pre { width: 280px; }
         }
        </style>
    </head>

    <body bgcolor="white">

            <span><H1>Server Error in '/DerekFoulk' Application.<hr width=100% size=1 color=silver></H1>

            <h2> <i>Could not load file or assembly 'dnx.clr.managed' or one of its dependencies. The system cannot find the file specified.</i> </h2></span>

            <font face="Arial, Helvetica, Geneva, SunSans-Regular, sans-serif ">

            <b> Description: </b>An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

            <br><br>

            <b> Exception Details: </b>System.IO.FileNotFoundException: Could not load file or assembly 'dnx.clr.managed' or one of its dependencies. The system cannot find the file specified.<br><br>

            <b>Source Error:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code>

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.</code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Assembly Load Trace:</b> The following information can be helpful to determine why the assembly 'dnx.clr.managed' could not be loaded.<br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

WRN: Assembly binding logging is turned OFF.
To enable assembly bind failure logging, set the registry value [HKLM\Software\Microsoft\Fusion!EnableLog] (DWORD) to 1.
Note: There is some performance penalty associated with assembly bind failure logging.
To turn this feature off, remove the registry value [HKLM\Software\Microsoft\Fusion!EnableLog].
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <b>Stack Trace:</b> <br><br>

            <table width=100% bgcolor="#ffffcc">
               <tr>
                  <td>
                      <code><pre>

[FileNotFoundException: Could not load file or assembly &#39;dnx.clr.managed&#39; or one of its dependencies. The system cannot find the file specified.]

[TypeLoadException: The domain manager specified by the host could not be instantiated.]
   System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException) +556

[HttpException (0x80004005): The domain manager specified by the host could not be instantiated.]
   System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +579
   System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +112
   System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +726
</pre></code>

                  </td>
               </tr>
            </table>

            <br>

            <hr width=100% size=1 color=silver>

            <b>Version Information:</b>&nbsp;Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.6.57.0

            </font>

    </body>
</html>
<!-- 
[FileNotFoundException]: Could not load file or assembly &#39;dnx.clr.managed&#39; or one of its dependencies. The system cannot find the file specified.
   at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
   at System.Activator.CreateInstance(String assemblyString, String typeName, Boolean ignoreCase, BindingFlags bindingAttr, Binder binder, Object[] args, CultureInfo culture, Object[] activationAttributes, Evidence securityInfo, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstance(String assemblyName, String typeName)
   at System.AppDomain.CreateInstanceAndUnwrap(String assemblyName, String typeName)
   at System.AppDomain.CreateAppDomainManager()
[TypeLoadException]: The domain manager specified by the host could not be instantiated.
   at System.AppDomain.CreateAppDomainManager()
   at System.AppDomain.Setup(Object arg)
   at System.AppDomain.nCreateDomain(String friendlyName, AppDomainSetup setup, Evidence providedSecurityInfo, Evidence creatorsSecurityInfo, IntPtr parentSecurityDescriptor)
   at System.AppDomain.InternalCreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at System.AppDomain.CreateDomain(String friendlyName, Evidence securityInfo, AppDomainSetup info)
   at AspNet.Loader.Bootstrapper.LoadApplicationNet45(String appId, String appConfigPath, IProcessHostSupportFunctions supportFunctions, LoadApplicationData* pLoadAppData, Int32 loadAppDataSize, String runtimePackagePath, String appBasePath)
   at AspNet.Loader.Bootstrapper.LoadApplication(String appId, String appConfigPath, IProcessHostSupportFunctions supportFunctions, LoadApplicationData* pLoadAppData, Int32 loadAppDataSize)
   at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
   at System.Web.Hosting.ProcessHost.System.Web.Hosting.IProcessHostLite.ReportCustomLoaderError(String appId, Int32 hr, AppDomain newlyCreatedAppDomain)
--- End of stack trace from previous location where exception was thrown ---
   at System.Web.Hosting.ApplicationManager.CreateAppDomainWithHostingEnvironment(String appId, IApplicationHost appHost, HostingEnvironmentParameters hostingParameters)   at System.Web.HttpRuntime.HostingInit(HostingEnvironmentFlags hostingFlags, PolicyLevel policyLevel, Exception appDomainCreationException)
[HttpException]: The domain manager specified by the host could not be instantiated.
   at System.Web.HttpRuntime.FirstRequestInit(HttpContext context)
   at System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context)
   at System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context)
-->

上面的代码片段在页面底部有一些关于错误的详细信息,但我无法解释它们...

我不认为出版是问题所在。我认为我在 IIS 中做错了......无论如何,任何关于如何将 MVC 6 应用程序发布到本地 IIS 的建议将不胜感激!谢谢!


更新

有趣的观察...我尝试按照以下说明将 Web 应用程序部署到 Microsoft Azure:https://azure.microsoft.com/en-us/documentation/articles/cloud-services-continuous-delivery-use-vso-git/

该应用程序在我的本地计算机上构建良好,没有错误,但是当我尝试使用 Git/Team 服务集成部署到 Azure 时,我收到以下错误:

body {
  font-family: Verdana, sans-serif;
}

span {
  color: #c00;
  font-weight: bold;
  font-style: italic;
}
Build started 6/25/2015 9:50:58 PM.<br>
&nbsp;&nbsp;&nbsp;&nbsp;1>Project "C:\a\src\DerekFoulk.sln" on node 1 (default targets).<br>
&nbsp;&nbsp;&nbsp;&nbsp;1>ValidateSolutionConfiguration:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Building solution configuration "Debug|Any CPU".<br>
&nbsp;&nbsp;&nbsp;&nbsp;1>Project "C:\a\src\DerekFoulk.sln" (1) is building "C:\a\src\src\DerekFoulk\DerekFoulk.xproj" (2) on node 1 (default targets).<br>
&nbsp;&nbsp;&nbsp;&nbsp;2>PrepareForBuild:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Creating directory "..\..\artifacts\obj\DerekFoulk\Debug\".<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;PreComputeCompileTypeScript:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C:\Program Files (x86)\Microsoft SDKs\TypeScript.4\tsc.exe  --noEmitOnError COMPUTE_PATHS_ONLY<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CompileTypeScript:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Skipping target "CompileTypeScript" because it has no outputs.<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;GetRuntimeToolingPathTarget:<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span>Cannot find DNX runtime dnx-clr-win-x86.1.0.0-beta4 in the folder: C:\Users\buildguest\.dnx\runtimes</span><br>
&nbsp;&nbsp;&nbsp;&nbsp;2>C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.targets(117,5): error : The Dnx Runtime package needs to be installed. See output window for more details. [C:\a\src\src\DerekFoulk\DerekFoulk.xproj]<br>
&nbsp;&nbsp;&nbsp;&nbsp;2>Done Building Project "C:\a\src\src\DerekFoulk\DerekFoulk.xproj" (default targets) -- FAILED.<br>
&nbsp;&nbsp;&nbsp;&nbsp;1>Done Building Project "C:\a\src\DerekFoulk.sln" (default targets) -- FAILED.<br>
<br>
Build FAILED.<br>
<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"C:\a\src\DerekFoulk.sln" (default target) (1) -><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"C:\a\src\src\DerekFoulk\DerekFoulk.xproj" (default target) (2) -><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(GetRuntimeToolingPathTarget target) -> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.targets(117,5): error : The Dnx Runtime package needs to be installed. See output window for more details. [C:\a\src\src\DerekFoulk\DerekFoulk.xproj]<br>
<br>
&nbsp;&nbsp;0 Warning(s)<br>
&nbsp;&nbsp;1 Error(s)<br>
<br>
Time Elapsed 00:00:10.40<br>

所以我无法使用默认的 .NET 5/MVC 6 Web 应用程序做任何事情?字面意思只能预览?


更新

我能够使用 Build > Publish > Microsoft Azure Web Apps 将站点作为 Web App 发布到 Azure,但即使删除所有内容并从头开始,我也无法从源代码管理 (Git) / Visual Studio Team Services 获取 Continuous Deployment 进行部署。构建失败,仍然说

Build (-1, 0) Exception Message: MSBuild error 1 has ended this build. You can find more specific information about the cause of this error in above messages. (type BuildProcessTerminateException) Exception Stack Trace: at System.Activities.Statements.Throw.Execute(CodeActivityContext context) at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation) C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\DNX\Microsoft.DNX.targets (117, 0) The Dnx Runtime package needs to be installed. See output window for more details.

是否有人能够通过 Git/Visual Studio Team Services 设置持续部署?如果可以,怎么做?!


更新(从 Git/Team 服务持续构建)

因此,构建失败时可能会出现以下问题:

Now we can build the solution. Since the default web template targets both the full .NET and .NET Core, we expect the build to fail when it tries to access the Environment.MachineName and Environment.OSVersion variables in HomeController. This behavior won’t work in .NET Core (currently), so we can comment it out. Open project.json and modify the “frameworks” key as shown:

"frameworks": {
    "dnx451": { }/*,
    "dnxcore50": { }*/
},

更新

以下是失败构建的日志文件: OneDrive - Log Files 希望有人看到这一点并可以帮助我解决问题,以便在我推送提交时我的站点将部署到 Azure。在开发过程中会很棒!

这有点难说,但可能是由于您的目标发布路径和 IIS 应用物理路径不匹配...

目标位置:c:\inetpub\wwwroot\DerekFoulk.com

对比

物理路径:C:\inetpub\wwwroot\DerekFoulk.com\wwwroot

这将特别有助于解决 DnxRuntime 问题。

当 VS Team Services 构建时,它需要我们用来在开发 PC 上构建的所有东西。

基本上,您创建一个预构建脚本来下载 dnvm、安装它并最终为每个 project.json 文件调用 dnu restore。最好将所有代码都放在 src 子目录中并有一个 global.json 文件。

我的解决方案基于这篇文章,您可以在其中找到脚本:https://msdn.microsoft.com/en-us/Library/vs/alm/Build/azure/deploy-aspnet5

感谢 post,希望我的回答对大家有所帮助。关于 "Could not load file or assembly 'dnx.clr.managed' or one of its dependencies.",我 运行 陷入了与 post 错误相同的错误 我没有注意到在我的应用程序池中启用 32 位应用程序被设置为 "False"。将其设置为 "True" 解决了我的问题。

关于部署到 Azure:

正如 Danie Sharpe 所提到的,https://msdn.microsoft.com/Library/vs/alm/Build/azure/deploy-aspnet5 which I got working. The one change I needed to make I mention in my answer to this question

一个略有不同的路线是不使用 Visual Studio 发布(在 VS Team Services 上),而是使用 DNU 发布命令。我在博客 post 中详细介绍了这一点,您可以在这里找到:http://devonburriss.me/aspnet-vsonline-ci/

让我们知道您的进展情况。看起来你已经在这上面花了很多时间了。

部署过程得到解释here。花几分钟时间阅读帖子中涉及 IIS 上 .NET 应用程序托管模型更改的链接。

在确保我的服务器上安装了正确的 .NET 版本后(我使用 DNVM),我能够启动我的应用程序并 运行 在我的本地 IIS 机器上。

希望对大家有所帮助!