Reference netstandard 2.0 types in ASP.NET MVC 5 razor views in .NET 4.7.1

这一生的挚爱 提交于 2019-12-02 20:54:55
Alex Ghiondea - MSFT

I looked at the solution (awesome explanation @Nicholas Petersen !!) and I see that at Razor compilation time you are missing the reference to netstandard.dll (which is what the error is about).

I added it to the list of assemblies used during compilation like this:

<add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />

The section I now have looks like this:

<system.web>
    <compilation>
        <assemblies>
            <add assembly="System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
            <add assembly="netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" />
        </assemblies>
    </compilation>
</system.web>

With that change I was able to get both the IDE to show me Intellisense for the Model in the cshtml file and the page rendered!

This is running on .NET Framework 4.7.1 and I expect this to work on .NET Framework 4.7.2. as well.

Note: There will still be a red squiggle in the IDE with the error message about the Enum type missing. But as that does not impact functionality (the Intellisense works and the code runs) I hope that will be acceptable for now.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!