Skip to main content
 首页 » 编程设计

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

2024年04月18日36dyllove98

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

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。 - 注意:您需要选择预发布选项。

安装后您将能够看到它。

尝试发布到我的本地驱动器本身并顺利发布

完成构建日志,

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