VS2017 ASP.NET Core 發佈與執行問題兩則

栏目: ASP.NET · 发布时间: 6年前

内容简介:前幾天研究過使用 VS2017 修改專案屬性升級到 2.2,並微調 NuGet 參照版本,網站很順利升級,執行結果看起也都正常。

前幾天研究過 ASP.NET Core 2.0 升級 2.2 ,今天手癢把部落格也從 ASP.NET Core 2.1 升到 2.2,遇到兩起小問題,學到一點新經驗,記錄如下:

VS2017 建置與執行無誤,但發佈(Publish)出錯

使用 VS2017 修改專案屬性升級到 2.2,並微調 NuGet 參照版本,網站很順利升級,執行結果看起也都正常。

VS2017 ASP.NET Core 發佈與執行問題兩則

但發佈出現以下錯誤:

C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.app\2.2.0\build\netcoreapp2.2\Microsoft.AspNetCore.App.targets(14,5): Error : This version of Microsoft.AspNetCore.App is only compatible with the netcoreapp2.2 target framework. Please target netcoreapp2.2 or choose a version of Microsoft.AspNetCore.App compatible with netcoreapp2.1.

研究後發覺是個笨問題,VS2017 發佈設定位於 \Properties\PublishProfiles\XXX.pubxml,使用 IDE 變更 .NET Core 版本時不會連帶更新,但只要開啟以下設定畫面,.pubxml 裡的 TargetFramework 即會與 .csproj 同步。

VS2017 ASP.NET Core 發佈與執行問題兩則

另外發現新版 VS2017 .pubxml 已不再需要標註 TargetFramework 即可運作,故可選擇手動將版本設定移除,或是砍掉 .pubxml 重新設定即可套用新規格。

ASP.NET Core 在 IISExpress 與 Kestrel 的執行結果可能不同

使用 VS2017 升級並測試 OK 後,開開心心將檔案部署到 Docker 卻晴天霹靂 - 網站開不起來! 由 Docker Log 得到以下訊息:

darkblog    | fail: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
darkblog    |       An unhandled exception has occurred while executing the request.
darkblog    | System.TypeLoadException: Could not load type 'Microsoft.AspNetCore.Mvc.TagHelpers.Internal.FileVersionProvider' from assembly 'Microsoft.AspNetCore.Mvc.TagHelpers, Version=2.2.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
darkblog    |    at WebOptimizer.Asset.GenerateCacheKey(HttpContext context)
darkblog    |    at WebOptimizer.Taghelpers.BaseTagHelper.GenerateHash(IAsset asset)
darkblog    |    at WebOptimizer.Taghelpers.LinkTagHelper.Process(TagHelperContext context, TagHelperOutput output)
darkblog    |    at Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
darkblog    |    at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.RunAsync(TagHelperExecutionContext executionContext)

原以為跟 Docker 環境有關,測試比對確認這個錯誤用 Kestrel 執行才會發生,用 IIS Express 執行時正常。Kestrel 與 IISExress 的環境差異會影響到 Razor.TagHelpers 層次有些出乎我的意料。

VS2017 ASP.NET Core 發佈與執行問題兩則

推測錯誤源自相關程式庫版本過舊,與 .NET Core 2.2 不相容,由 WebOptimizer 關鍵字很快找到嫌犯 - LigerShark.WebOptimizer.Core ,而問題也在將 WebOptimizer.Core.dll 由 1.0.215 升級至 1.0.236 後排除。

由此再學到經驗一則:

ASP.NET Core 以 IISExpress/IIS 或 Kestrel 執行的結果可能不同,需個別測試

順便一提,部落格目前已換版升到 ASP.NET Core 2.2,大家如發現隱藏 Bug 請再回報給我,感謝!

ASP.NET Core 2.2 upgrade notes: if build and run OK but publish failed, check the .pubxml. Running at IISExpress or Kestrel may get different results.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Netty实战

Netty实战

诺曼·毛瑞尔(Norman Maurer)、马文·艾伦·沃尔夫泰尔(Marvin Allen Wolfthal) / 何品 / 人民邮电出版社 / 2017-5-1 / 69.00

编辑推荐 - Netty之父”Trustin Lee作序推荐 - 阿里巴巴中间件高级技术专家为本书中文版作序推荐 - 系统而详细地介绍了Netty的各个方面并附带了即用型的优质示例 - 附带行业一线公司的案例研究 - 极实用的Netty技术书 无论是构建高性能的Web、游戏服务器、推送系统、RPC框架、消息中间件还是分布式大数据处理引擎,都离不开Nett......一起来看看 《Netty实战》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试