MvcBuildViews not working for x64 project


In a VS2017 ASP.NET MVC project I've noticed that my views aren't syntax checked on build/compile even though I have set MvcBuildViews to true. The project is now on MVC 5 but has been upgraded from some earlier version. It also started out being set to AnyCPU but it's now set to x64 (we need a lot of data in memory sometimes, and we always deploy to x64, so...).

I've checked that the .csproj contains the build target that has been mentioned in various places, including several in SO answers. I've tried a few variations, but none has worked.

This is the one that was present but commented out in the .csproj when I started investigating:

<Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build">
  <Message Importance="normal" Text="Precompiling views" />
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />

If i uncomment it, I get a build error (I've manually translated it from Swedish):

Failed to read the file or assembly MyProjectName or one of its dependencies. An attempt to read a program with invalid format was made.

File: C:\...MyProjectPath...\ASPNETCOMPILER

It was suggested here to specify the x64 ASP.NET compiler: Add this below the <MvcBuildViews> tag:

<AspNetToolPath Condition="'$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>

And add attribute ToolPath="$(AspNetToolPath)" to the target's <AspNetCompiler.../> tag.

Doing so results in another error (again translated by me from Swedish):

Failed to read the file or assembly System.Runtime.InteropServices.RuntimeInformation, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies. The found assembly's manifest definition doesn't match the assembly reference. (Exception from HRESULT: 0x80131040)

File: C:\temp\global.asax

The assembly in question is pulled into the project by our use of a Stripe card payment NuGet package, which was added after the project was changed from AnyCPU to x64. The System.Runtime.InteropServices.RuntimeInformation package is installed in version 4.3.0. The web.config contains this binding redirect (why don't the version numbers match 4.3.0?):

  <assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
  <bindingRedirect oldVersion="" newVersion=""/>

At this point, I'm out of ideas, what to try next. Can anyone help?
asked on Stack Overflow Feb 11, 2021 by Kjell Rilbe

1 Answer


Try to register that dll into GAC:

Try these:

1) run update-package -reinstall under Tools-->Nuget Package Manager-->Package Manager Console

2) open developer command prompt for VS as Administrator and then type:

cd C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.3.0\lib\net45

gacutil /i System.Runtime.InteropServices.RuntimeInformation.dll

Also, you can download system.runtime.interopservices.runtimeinformation nuget package version 4.0.0.

After that, register that dll under C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.0.0\lib\net45.

Besides, there is a similar issue.

answered on Stack Overflow Feb 12, 2021 by Perry Qian-MSFT

User contributions licensed under CC BY-SA 3.0