[英]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
.在 VS2017 ASP.NET MVC 项目中,我注意到我的视图在构建/编译时没有进行语法检查,即使我已将
MvcBuildViews
设置为true
。 The project is now on MVC 5 but has been upgraded from some earlier version.该项目现在在 MVC 5 上,但已从一些早期版本升级。 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...).
它也开始设置为 AnyCPU,但现在设置为 x64(有时我们需要 memory 中的大量数据,我们总是部署到 x64,所以......)。
I've checked that the .csproj
contains the build target that has been mentioned in various places, including several in SO answers.我检查了
.csproj
是否包含在各个地方提到的构建目标,包括 SO 答案中的几个。 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:这是我开始调查时存在但在
.csproj
中注释掉的那个:
<Target Name="BuildViews" Condition="'$(MvcBuildViews)'=='true'" AfterTargets="Build">
<Message Importance="normal" Text="Precompiling views" />
<AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
</Target>
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.
未能读取文件或程序集 MyProjectName 或其依赖项之一。 An attempt to read a program with invalid format was made.
试图读取格式无效的程序。
File: C:\...MyProjectPath...\ASPNETCOMPILER
文件:
C:\...MyProjectPath...\ASPNETCOMPILER
It was suggested here to specify the x64 ASP.NET compiler: Add this below the <MvcBuildViews>
tag:这里建议指定 x64 ASP.NET 编译器:在
<MvcBuildViews>
标签下面添加:
<AspNetToolPath Condition="'$(Platform)' == 'x64'">$(windir)\Microsoft.NET\Framework64\v4.0.30319</AspNetToolPath>
And add attribute ToolPath="$(AspNetToolPath)"
to the target's <AspNetCompiler.../>
tag.并将属性
ToolPath="$(AspNetToolPath)"
添加到目标的<AspNetCompiler.../>
标记。
Doing so results in another error (again translated by me from Swedish):这样做会导致另一个错误(我再次从瑞典语翻译):
Failed to read the file or assembly System.Runtime.InteropServices.RuntimeInformation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a or one of its dependencies.
无法读取文件或程序集 System.Runtime.InteropServices.RuntimeInformation,Version=4.0.0.0,Culture=neutral,PublicKeyToken=b03f5f7f11d50a3a 或其依赖项之一。 The found assembly's manifest definition doesn't match the assembly reference.
找到的程序集的清单定义与程序集引用不匹配。 (Exception from HRESULT: 0x80131040)
(来自 HRESULT 的异常:0x80131040)
File: C:\temp\global.asax
文件:
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.我们使用 Stripe 卡付款 NuGet package 将相关组件拉入项目,这是在项目从 AnyCPU 更改为 x64 后添加的。 The
System.Runtime.InteropServices.RuntimeInformation
package is installed in version 4.3.0. System.Runtime.InteropServices.RuntimeInformation
package 安装在版本 4.3.0 中。 The web.config
contains this binding redirect (why don't the version numbers match 4.3.0?): web.config
包含此绑定重定向(为什么版本号不匹配 4.3.0?):
<dependentAssembly>
<assemblyIdentity name="System.Runtime.InteropServices.RuntimeInformation" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.0" newVersion="4.0.1.0"/>
</dependentAssembly>
At this point, I'm out of ideas, what to try next.在这一点上,我没有想法,下一步该尝试什么。 Can anyone help?
任何人都可以帮忙吗?
Try to register that dll into GAC:尝试将 dll 注册到 GAC 中:
Try these:试试这些:
1) run update-package -reinstall
under Tools --> Nuget Package Manager --> Package Manager Console 1)在Tools --> Nuget Package Manager --> Package Manager Console下运行
update-package -reinstall
2) open developer command prompt for VS as Administrator and then type: 2)以管理员身份打开VS的开发人员命令提示符,然后键入:
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
.另外,您可以下载 system.runtime.interopservices.runtimeinformation
system.runtime.interopservices.runtimeinformation
package 版本4.0.0
。
After that , register that dll under C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.0.0\lib\net45
.之后,在
C:\Users\xxx\.nuget\packages\system.runtime.interopservices.runtimeinformation\4.0.0\lib\net45
。
Besides, there is a similar issue .此外,还有一个类似的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.