title: Reference netstandard 2.0 types in ASP.NET MVC 5 razor views in .NET 4.7.1
body: <p>.NET 4.7.1 was supposed to solve problems we had in referencing <code>netstandard 2.0</code> libraries from the full framework. It sort of did, despite some continuing and painful dll conflict warnings and related problems, and the need to manually update to PackageReferences (<a href="https://marketplace.visualstudio.com/items?itemName=CloudNimble.NuGetPackageReferenceUpgrader" rel="noreferrer">see this wondeful extension</a>). Nonetheless, one can get it working, though see note 1 below, and if I may say: it is unfortunate to say the least that there has been no VStudio help or much guidance on this and related issues, till now one has to find such help on back channels on github. This very problem itself ideally would have been messaged: ASP.NET MVC 5 does NOT yet support netstandard in razor ... wish they would just have messaged us that if true! Would save <em>endless</em> wasted hours! But is that the case? Or is there a fix?</p>
  
  <p>Here then is the problem with ASP.NET MVC 5 projects (even those targeting 4.7.1). Although plain .cs code works, including in controllers, this is <em>not</em> true for any code within razor views (<code>.cshtml</code> files). Any types referenced within razor views that came from a <code>netstandard</code> library completely fail.  </p>
  
  <p>To reproduce this problem and make sure it wasn't just my own code, I reproduced this <a href="https://github.com/copernicus365/AspMvc5NetstandardCompatibility" rel="noreferrer">by making a bran new ASP.NET MVC 5 project (on github)</a> in the newest version of VStudio 2017 (even the Preview version, 15.7.0 Preview 4.0), then making a new <code>netstandard</code> project with just a couple of types in it, so I could practice referencing those types in the MVC 5 view pages. And sure enough, it still fails. For instance, this simple type from the netstandard project:</p>
  
  <pre><code>public enum AnimalType { Cat, Dog, Zebra, Alligator }
  </code></pre>
  
  <p>If you make that enum a type within your view model passed into the page, if you ever  reference that property in the razor page, you will get compile time errors and also at runtime, saying:</p>
  
  <blockquote>
    <p>The type 'Enum' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.  AspMvc5WebApp471</p>
  </blockquote>
  
  <p>As also detailed in that repo, I even tried to recompile my own version of <code>Microsoft.CodeDom.Providers.DotNetCompilerPlatform</code> to reference it within the <code>web.config</code>, but that didn't solve the problem.</p>
  
  <p>So it would be lovely to hear from the ASP.NET team or anyone else that might know how to fix this problem, what that fix might entail. Or if ASP.NET MVC 5 simply is not yet workable with <code>netstandard</code>, it would be nice to know if that is the message, and if support for <code>netstandard</code> might be coming to ASP.NET MVC 5 in the near future, or if it is on a roadmap somewhere? And perhaps what exactly is the thing causing this failure? Of course, it would be happiest to hear if there is a fix that can be applied right away, but either way, we need to know, otherwise <code>netstandard</code> is basically useless for those of us who can't just dump ASP.NET MVC 5 in a day (as much as we would like to, in the real world...) Much appreciated.</p>
  
  <p>(Note 1: Net Framework 4.7.1 was eagerly looked forward to by myself and many others when it was said for some time it would solve many of the pain points, but unfortunately it has introduced its own set of <a href="https://github.com/dotnet/sdk/issues/1647" rel="noreferrer">endless dll hell like problems</a>, or see <a href="https://github.com/dotnet/standard/issues/514" rel="noreferrer">here</a>, <a href="https://github.com/dotnet/standard/issues/391" rel="noreferrer">or here</a>, <a href="https://github.com/dotnet/corefx/issues/28833" rel="noreferrer">or here</a>. See for instance the discussions on <code>System.Net.Http</code> (and binding redirects do not just remove all of the conflict warnings, they often bring up their own, highly painful stuff). Now some have been hoping 4.7.2 would solve all these problems, though it didn't solve these ASP.NET MVC 5 problems for me)</p>