【问题标题】:Publishing causes a FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.ProjectModel'发布导致 FileNotFoundException:无法加载文件或程序集“Microsoft.DotNet.ProjectModel”
【发布时间】:2023-04-07 00:22:01
【问题描述】:

运行dotnet publish时出现错误:

dotnet restore
dotnet build
dotnet publish --configuration Release  --runtime active

发布成功,但我认为 IISIntergration/modifying web.config 部分有问题。

错误:

Configuring the following project for use with IIS: 'C:\Users\john-luke.laue\repositories\MyApp\src\MyApp\bin\Release\net461\active\publish'
Could not load file or assembly 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.
File name: 'Microsoft.DotNet.ProjectModel, Version=1.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'
at Microsoft.AspNetCore.Server.IISIntegration.Tools.PublishIISCommand.Run()
at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.<>c__DisplayClass0_0.<Main>b__0()
at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
at Microsoft.AspNetCore.Server.IISIntegration.Tools.Program.Main(String[] args)

project.json

{
"userSecretsId": "aspnet5-EspritWebMvc-20150831035846",
"version": "1.0.0-*",
"buildOptions": {
  "emitEntryPoint": true,
  "preserveCompilationContext": true,
  "warningsAsErrors": true
},
"dependencies": {
  "Microsoft.AspNetCore.Authentication.Cookies": "1.0.0",
  "Microsoft.AspNetCore.Authorization": "1.0.0",
  "Microsoft.AspNetCore.Diagnostics": "1.0.0",
  "Microsoft.AspNetCore.Hosting": "1.0.0",
  "Microsoft.AspNetCore.Hosting.Abstractions": "1.0.0",
  "Microsoft.AspNetCore.Http.Extensions": "1.0.0",
  "Microsoft.AspNetCore.Mvc": "1.0.0",
  "Microsoft.AspNetCore.Routing": "1.0.0",
  "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
  "Microsoft.AspNetCore.Session": "1.0.0",
  "Microsoft.AspNetCore.StaticFiles": "1.0.0",
  "Microsoft.Extensions.Caching.SqlServer": "1.0.0",
  "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0",
  "Microsoft.AspNetCore.Razor.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.Logging": "1.0.0",
  "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
  "Microsoft.DotNet.ProjectModel": "1.0.0-rc4-003206"
},

"frameworks": {
  "net461": {}
},


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


"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"
},

"scripts": {
  "postpublish": "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%"
},


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

}

我该如何调试或解决这个问题?

【问题讨论】:

    标签: asp.net-core asp.net-core-mvc .net-core asp.net-core-1.0


    【解决方案1】:

    This github 问题包含解决方案。您需要清除 nuget 缓存并恢复包(请参阅this 评论):

    1. 删除%USERPROFILE%\.nuget\packages\.tools\Microsoft.EntityFrameworkCore.Tools%USERPROFILE%\.nuget\packages\Microsoft.EntityFrameworkCore.Tools

    2. 确保您的“工具”部分与此匹配:

      "tools": {
          "Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final"
      }
      
    3. 重新运行dotnet restore

    【讨论】:

    • 非常感谢。我在一个单独的项目中有我的实体框架代码,它使用的是“Microsoft.EntityFrameworkCore.Tools”。所以我按照你说的做了,现在可以了!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-22
    • 1970-01-01
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 2011-09-29
    • 1970-01-01
    相关资源
    最近更新 更多