问题描述
我将我的 ASP.NET CORE 应用程序从 sdk .NET Core 2.0 升级到 .NET Core 2.1.我可以在我的本地主机中运行该解决方案,但是当我将它部署到另一台服务器时出现异常.例外情况如下.到目前为止,我为解决该问题所做的步骤如下,并且我所做的所有修改都引发了相同的错误,似乎没有任何效果.有没有人有任何建议如何解决这个问题?
I upgraded my ASP.NET CORE application from sdk .NET Core 2.0 to .NET Core 2.1.I can run the solution in my localhost but when I deploy it to another server there is an exception. And the exception is below.The steps I have done to solve the issue so far are below and it throws the same error with all the modification that I did seems nothing works.Does anybody have any suggestion how to solve this issue?
我已经完成的步骤:
修改项目设置
Modify the setting for the project
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<Platforms>AnyCPU;x64</Platforms>
<RuntimeFrameworkVersion>2.1.0</RuntimeFrameworkVersion>
<UseNETCoreGenerator>true</UseNETCoreGenerator>
<RazorCompileOnBuild>true</RazorCompileOnBuild>
</PropertyGroup>
我还在 web.config 中添加了绑定重定向
I also added binding redirect in the web.config
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"
bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0"
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-4.2.0.0" newVersion="4.2.1.0" />
</dependentAssembly>
</assemblyBinding>
在服务器上安装 .net core 2.1
Install .net core 2.1 on the server
异常:
Microsoft.AspNetCore.Mvc.Razor.Compilation.CompilationFailedException:发生一个或多个编译失败:错误 CS1705:程序集版本=1.0.0.0,Culture=neutral,PublicKeyToken=null'使用'System.Runtime,Version=4.2.1.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a',其版本高于引用的程序集'System.Runtime',标识为'System.Runtime,Version=4.2.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a'
推荐答案
我遇到了同样的问题.当我将解决方案中的 Views
文件夹添加到 publish
文件夹时,问题就消失了.出于某种原因,Razor 要求这些源文件存在于服务器中并且是最新的,即使它也将它们编译为 .dll.因此,在发布期间没有自动复制 Views 文件夹确实很奇怪.
I had same problem. When I added the Views
folder from the solution to the publish
folder then the problem went away. For some reason Razor requires these source files to be present in the server AND up-to-date even when it compiles them also into .dll. Therefore it is strange indeed that the Views folder is not automatically copied during publish.
我个人做了一个这样的路口连接MyProjectinReleaseetcoreapp2.1linux-x64publishViews"MyProjectViews"
I personally made a junction like thisjunction "MyProjectinReleaseetcoreapp2.1linux-x64publishViews" "MyProjectViews"
或者,禁用以下行可能会有所帮助(尚未测试但此问题似乎相关,因为在较早版本的 Net.Core 中没有 Razor 编译).
Alternatively, disabling the following line might help (have not tested but this issue seems to be related since in earlier versions of Net.Core there was no Razor compilation).
到
这篇关于System.Runtime, Version=4.2.1.0, PublicKeyToken=b03f5f7f11d50a3a 的版本高于引用的程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!