原文網址:https://blog.csdn.net/lihongzhai/article/details/79039160
今天遇到了很奇怪的現象,在Windows上發布的asp.net core app部署到linux上就不好用了。提示如下錯誤:
Error:
An assembly specified in the application dependencies manifest (Calculate24Web.deps.json) was not found:
package: ‘Microsoft.AspNetCore.Antiforgery’, version: ‘2.0.1’
path: ‘lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll’
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.3.xml
這個是我自己發布后在 Ubuntu 上運行時顯示的錯誤
Error:
An assembly specified in the application dependencies manifest (..deps.json) was not found:
package: 'Microsoft.AspNetCore.Antiforgery', version: '2.0.3'
path: 'lib/netstandard2.0/Microsoft.AspNetCore.Antiforgery.dll'
This assembly was expected to be in the local runtime store as the application was published using the following target manifest files:
aspnetcore-store-2.0.8.xml
把源碼拷貝到Linux的機器上,可以編譯,可以在開發模式下運行,(好像在Debug模式下還成功了),后來在Release模式下發布,就不能運行,提示上面的錯誤。
經過一天的倒騰,終於,最后,是個小問題。問題是asp.net 沒有把服務器需要的包全部發布出來,它認為是目標系統帶着有,而實際上目標系統中沒有。
解決辦法:
增加如下一行到 csjproj文件中即可:
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
最后csjproj文件看上去像這個樣子:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<PublishWithAspNetCoreTargetManifest>false</PublishWithAspNetCoreTargetManifest>
</PropertyGroup>