【问题标题】:Can't publish .NET Core Web Application (could not load file or assembly Microsoft.DotNet.ProjectModel)无法发布 .NET Core Web 应用程序(无法加载文件或程序集 Microsoft.DotNet.ProjectModel)
【发布时间】:2016-07-21 19:05:36
【问题描述】:

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

System.IO.FileNotFoundException:无法加载文件或程序集“Microsoft.DotNet.ProjectModel,版本=1.0.0.0,文化=中性,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,但均未成功。我错过了什么?

【问题讨论】:

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


    【解决方案1】:

    真的,我在配置文件中没有看到 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。 - 注意:您需要选择预发布选项。

    安装后就可以看到了。

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

    完整的构建日志,

    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

    【讨论】:

    • 抱歉,我已将它从我的 project.json 中删除,因为它不起作用,我忘了把它放回去。我的项目中的以下行仍然出现相同的错误。 json: "Microsoft.DotNet.ProjectModel": "1.0.0-rc3-003121"(更新主帖)
    • 当您检查管理 NuGet 包时,Microsoft.DotNet.ProjectModel 是否显示在已安装部分?如果是,只需单击卸载并重新安装即可。
    • 我刚刚安装的 rc3 版本的 ProjectModel 出现在已安装部分 - 我尝试按照您的建议卸载并重新安装,但仍然遇到相同的错误。该错误似乎正在寻找版本 1.0.0.0 - 但我能找到的只是发布候选包。我是否缺少 .NET Core SDK 的一部分?
    • 更新了现有评论..请检查。
    • 感谢您的更新,但是,按照相同的步骤,我仍然收到问题。唯一的区别是发布 - 我可以在 localhost 上运行程序就好了,但是当我尝试将它发布到 Azure 时,我遇到了问题。我的问题应该更清楚。这可能是 IIS 或 Azure 配置文件的问题吗?
    【解决方案2】:

    我在发布到 Azure 时遇到了完全相同的错误。对我有帮助的是在 project.json 中将 Microsoft.AspNetCore.Server.IISIntegration.Tools 更改为 1.0.0-preview1-final:

    "Microsoft.AspNetCore.Server.IISIntegration.Tools": {
      "version": "1.0.0-preview1-final",
      "imports": "portable-net45+win8+dnxcore50"
    },
    

    我必须说我不知道​​为什么会这样,所以欢迎任何见解

    【讨论】:

      【解决方案3】:

      由于我无法从其他任何人那里得到重现,我重新安装了操作系统、Visual Studio 以及我工作站上的所有部件,现在它可以正常工作了。仍然不确定潜在问题来自哪里,但它似乎是在 ASP.NET Core 1.0 发布前后的某个时候在我的机器上输入的一种奇怪状态

      【讨论】:

        猜你喜欢
        • 2023-04-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-05-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多