c# - 无法发布 .NET Core Web 应用程序(无法加载文件或程序集 Microsoft.DotNet.ProjectModel)

标签 c# asp.net azure visual-studio-2015

我一直在尝试发布我的应用程序,但总是遇到错误:

System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.DotNet.ProjectModel,Version=1.0.0.0,Culture=neutral,PublicKeyToken=adb9793829ddae60”。系统找不到指定的文件。

我认为我的项目可能有问题,但按照以下步骤创建空白模板项目,我遇到了完全相同的问题:

1 - Visual Studio 2015(已安装更新 3 和补丁)=> 文件 => 新建 => 项目 => 具有单独用户帐户的 ASP.NET Core Web 应用程序 (.NET Core)

2 - 右键单击​​项目 => 发布 => 选择我的 Azure 配置文件 => 单击发布

3 - 发布失败并出现上述错误

这是我的project.json:

  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore": "1.0.0",
    "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "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.EntityFrameworkCore.SqlServer": "1.0.0",
    "Microsoft.EntityFrameworkCore.SqlServer.Design": {
      "version": "1.0.0",
      "type": "build"
    },
    "Microsoft.EntityFrameworkCore.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.UserSecrets": "1.0.0",
    "Microsoft.Extensions.Logging": "1.0.0",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Logging.Debug": "1.0.0",
    "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
    "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.VisualStudio.Web.CodeGenerators.Mvc": {
      "version": "1.0.0-preview2-final",
      "type": "build"
    },
    "Microsoft.DotNet.ProjectModel": "1.0.0-rc3-003121"
  },

  "tools": {
    "BundlerMinifier.Core": "2.0.238",
    "Microsoft.AspNetCore.Razor.Tools": "1.0.0-preview2-final",
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final",
    "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
    "Microsoft.Extensions.SecretManager.Tools": "1.0.0-preview2-final",
    "Microsoft.VisualStudio.Web.CodeGeneration.Tools": {
      "version": "1.0.0-preview2-final",
      "imports": [
        "portable-net45+win8"
      ]
    }
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

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

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

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

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

我尝试在 Nuget 中找到丢失的包,并尝试将其手动添加到 project.json,但都没有成功。我错过了什么?

最佳答案

真的,我在配置文件中没有看到 ProductModel。

您能否通过包管理器控制台尝试Install-Package Microsoft.DotNet.ProjectModel -Pre。或右键单击该项目并选择“管理 NuGet 包”并搜索 Microsoft.DotNet.ProjectModel 并安装它。

然后检查package.json,必须有一个部分Microsoft.DotNet.ProjectModel

根据评论更新

尝试了以下步骤来显示。

  1. 创建一个新的 .Net Core Web 应用程序。
  2. 右键单击“引用”并选择“管理 NuGet 包”。
  3. 在浏览部分中搜索 Microsoft.DotNet.ProjectModel。 - 注意:您需要选择预发布选项。

安装后您将能够看到这一点。

enter image description here

尝试发布到我的本地驱动器本身并发布,没有任何问题

enter image description here

完整的构建日志,

1>------ Build started: Project: dotmodelissue, Configuration: Release Any CPU ------
1>  C:\Program Files\dotnet\dotnet.exe build "E:\Thenna\StackOverFlow\dotmodelissue" --configuration Release --no-dependencies
1>  Project dotmodelissue (.NETCoreApp,Version=v1.0) will be compiled because expected outputs are missing
1>  Compiling dotmodelissue for .NETCoreApp,Version=v1.0
1>  Compilation succeeded.
1>      0 Warning(s)
1>      0 Error(s)
1>  Time elapsed 00:00:01.7973890
1>
2>------ Publish started: Project: dotmodelissue, Configuration: Release Any CPU ------
Connecting to E:\ddd...
Environment variables:
Path=.\node_modules\.bin;D:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External;%PATH%;D:\Program Files (x86)\Microsoft Visual Studio 14.0\Web\External\git
C:\Program Files\dotnet\dotnet.exe publish "E:\Thenna\StackOverFlow\dotmodelissue" --framework netcoreapp1.0 --output "C:\Users\thenna\AppData\Local\Temp\PublishTemp\dotmodelissue57" --configuration Release --no-build
Publishing dotmodelissue for .NETCoreApp,Version=v1.0
Configuring the following project for use with IIS: 'C:\Users\thenna\AppData\Local\Temp\PublishTemp\dotmodelissue57'
Updating web.config at 'C:\Users\thenna\AppData\Local\Temp\PublishTemp\dotmodelissue57\web.config'
Configuring project completed successfully
publish: Published to C:\Users\thenna\AppData\Local\Temp\PublishTemp\dotmodelissue57
Published 1/1 projects successfully
Publishing with publish method [FileSystem]
Publishing files to E:\ddd
Executing command ["C:\Program Files (x86)\IIS\Microsoft Web Deploy V3\msdeploy.exe" -source:manifest='C:\Users\thenna\AppData\Local\Temp\PublishTemp\obj\dotmodelissue57\SourceManifest.xml' -dest:manifest='C:\Users\thenna\AppData\Local\Temp\PublishTemp\obj\dotmodelissue57\DestinationManifest.xml' -verb:sync -retryAttempts:20 -disablerule:BackupRule]
Total changes: 204 (125 added, 79 deleted, 0 updated, 0 parameters changed, 5540847 bytes copied)

Web App was published successfully file:///E:/ddd

========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
========== Publish: 1 succeeded, 0 failed, 0 skipped ==========

发布到 Azure

enter image description here

关于c# - 无法发布 .NET Core Web 应用程序(无法加载文件或程序集 Microsoft.DotNet.ProjectModel),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38512468/

相关文章:

c# - 从 Rectangle.Intersects() 获取碰撞细节

c# - 使用 ServiceStack.Redis 对高容量场景的意外回复

azure - 如何使用Azure逻辑应用程序一次将一堆消息发送到Azure存储队列?

azure - 具有 azure 函数的事件中心分区计数涉及的权衡

azure - 资源组范围内的部署不允许使用位置属性

c# - 在 visual studio 中是否有智能感知 lambda 的热键?

c# - FORWARD_NULL 在取消引用 null 之后?

asp.net - 在 ASP.NET 中动态创建带有缩进线的 TreeViewin HTML

ASP.NET MVC bundle - 仅在 Debug模式下包含脚本

c# - 用户登录成功后未通过身份验证