发布 ASP.NET 核心网络应用程序时缺少 DLL

Missing DLL's when publishing ASP.NET Core web app

当我发布我的 ASP.NET 核心 (v1.0.0) MVC 6 应用程序时,它无法 运行 在查看任何页面时成功(即 server/host 启动正常但是发出 GET 请求时抛出错误)。在命令提示符处启动应用程序时,我可以看到它抱怨缺少 DLL。我将丢失的 DLL 添加到已发布的目录(应用程序由 IIS/Krestel 托管),然后它抱怨另一个 DLL,然后是另一个,依此类推。最终,在一切 运行 成功之前,它需要以下 DLL:

Microsoft.DotNet.Cli.Utils.dll
Microsoft.DotNet.ProjectModel.dll
Microsoft.Extensions.CommandLineUtils.dll
NuGet.Common.dll
NuGet.Configuration.dll
NuGet.DependencyResolver.Core.dll
NuGet.Frameworks.dll
NuGet.LibraryModel.dll
NuGet.Packaging.Core.dll
NuGet.Packaging.Core.Types.dll
NuGet.Packaging.dll
NuGet.ProjectModel.dll
NuGet.Protocol.Core.Types.dll
NuGet.Protocol.Core.v3.dll
NuGet.Repositories.dll
NuGet.RuntimeModel.dll
NuGet.Versioning.dll

我不确定为什么已发布的 Web 应用程序需要 NuGet DLL,或者为什么会发生这种情况。显然 Visual Studio 应该为我们处理这类事情。现在,当我发布时,我没有先清除所有文件(所以我手动复制的 DLL 留在那里)但我想知道为什么,如果需要这些 DLL,它们是否不包含在部署过程中?

这是我的 project.json,以防有帮助:

{
  "dependencies": {
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Mvc": "1.0.0",
    "Microsoft.AspNetCore.Razor.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
    "Microsoft.AspNetCore.StaticFiles": "1.0.0",
    "Microsoft.AspNetCore.Session": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Serilog.Extensions.Logging": "1.2.0",
    "Serilog.Sinks.File": "2.2.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "System.Data.Common": "4.1.0",
    "System.Data.SqlClient": "4.1.0",
    "System.DirectoryServices.Linq": "1.2.2.1",
    "Microsoft.Extensions.Logging.Filter": "1.0.0",
    "BundlerMinifier.Core": "2.2.281"
  },

  "tools": {
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "net462": {}
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "Views",
      "appsettings.json",
      "web.config"
    ]
  },

  "scripts": {
    "prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ],
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  },

  "configurations": {
    "DEV": {
      "compilationOptions": { "define": [ "DEV" ] },
      "buildOptions": { "define": [ "DEV" ] }
    },
    "PROD_SRV": {
      "compilationOptions": { "define": [ "TEST_SRV" ] },
      "buildOptions": { "define": [ "TEST_SRV" ] }
    },
    "PROD_SRV_DEV": {
      "compilationOptions": { "define": [ "TEST_SRV_DEV" ] },
      "buildOptions": { "define": [ "TEST_SRV_DEV" ] }
    },
    "TEST": {
      "compilationOptions": { "define": [ "TEST" ] },
      "buildOptions": { "define": [ "TEST" ] }
    },
    "TEST_SRV": {
      "compilationOptions": { "define": [ "TEST_SRV" ] },
      "buildOptions": { "define": [ "TEST_SRV" ] }
    },
    "TEST_SRV_DEV": {
      "compilationOptions": { "define": [ "TEST_SRV_DEV" ] },
      "buildOptions": { "define": [ "TEST_SRV_DEV" ] }
    }
  }
}

有什么想法吗?

谢谢大家!

嗯,我解决了这个问题。我创建了一个新的 ASP.NET Core (.NET Framework) Web 应用程序项目并且能够毫无问题地发布。所以我将项目中的值.json/global.json 文件与我项目中的版本进行了比较。我将所有版本更新为 project.json 中的最新版本,但这并没有解决问题。但是在将 global.json 中的密钥 "sdk:version" 更新为“1.0.0-preview2-003131”后,它起作用了。我不敢相信这就是问题所在,但它确实有效。

在经历了很多头痛之后,我也能够让 Web Deploy 正常工作。光是发布就太费劲了!