如何在编译时或为ASP.NET视图编译时引用强命名的DLL? [英] How to reference a strongly-named DLL at compile time, or for ASP.NET view compilation?

查看:67
本文介绍了如何在编译时或为ASP.NET视图编译时引用强命名的DLL?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ASP.NET 4.7.2 Framework项目.在运行时,加载视图时,提示找不到System.Runtime版本4.0.0.0.我们已经在这里广泛地写过:

已经过去了一个星期,我们仍然没有解决方案.所有开发都已停止.

昨天我们仅通过调用应用程序启动来尝试并行加载:

  Assembly systemRuntime = Assembly.Load("System.Runtime,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"); 

启动时.我们对 systemRuntime 不做任何事情.只有这样我们才能确认确实加载了4.0.0.0.不幸的是,那并没有解决任何问题.

这使我认为也许是因为视图是在运行时编译的,也许是由于某种原因它们没有引用正确的System.Runtime,或者我们需要在那里并行加载.

这个问题非常严重,我们已经开始将网站移植到.NET Core,因为没有人知道如何解决它.根据分析器,我们将不得不重写大约15%的站点.我们可能要花数周的时间才能部署到生产环境,因此必须在物理上尽快找到一个临时解决方案.我们已经有需要修复的补丁.

Dai在第一条评论中向我指示了正确的方向:视图引擎不一定使用与主项目相同的引用.

在谷歌搜索后,我找到了一种引用视图引擎程序集的方法.在web.config中:

 < configuration>...< system.web>< compilation debug ="true" targetFramework ="4.7.2" batch ="false"><装配体>< add assembly ="System.Runtime,Version = 4.0.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a"/></assembly></compilation></system.web>...</configuration> 

我还遵循了戴的建议,尝试预编译视图.通过使用以下命令编辑MVC项目的.csproj文件来完成此操作:

 < MvcBuildViews> true</MvcBuildViews> 

不必对视图进行预编译,但确实证明了它的视图确实与主项目不同,并且使测试速度加快了一点,因为我不必运行该站点即可看到它崩溃./p>

I have an ASP.NET 4.7.2 Framework project. At runtime, upon loading a view, it says System.Runtime version 4.0.0.0 cannot be found. We have written about this extensively here: ASP.NET: .NET Framework/Standard/Core DLL collisions, caused by Nuget. "You must add a reference to assembly System.Runtime..."

It's been over a week and we still don't have a solution. All development has been halted.

Yesterday we tried side-by-side loading by simply calling on application start up:

Assembly systemRuntime = Assembly.Load("System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a");

Upon start up. We don't do anything with systemRuntime. It's only there for us to confirm that indeed 4.0.0.0 was loaded. Unfortunately, that didn't fix anything.

This makes me think that maybe since views are compiled at run-time, maybe somehow they are not referencing the right System.Runtime, or that we need to do the side-by-side loading there.

This problem is so severe we've started porting the site to .NET Core, because no one has any ideas how to solve it. According to analyzer, we'll have to rewrite approximately 15% of the site. We cannot go without deploying to production for potentially weeks, so a temporary solution must be found as soon as physically possible. We already have fixes that need to go to up.

解决方案

Dai, in the first comment, directed me in the right direction: the view engine doesn't necessarily use the same references as the main project.

After some Googling, I found a way to reference assemblies for the view engine. In web.config:

<configuration>
...
  <system.web>
    <compilation debug="true" targetFramework="4.7.2" batch="false">
      <assemblies>
        <add assembly="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
      </assemblies>
    </compilation>
  </system.web>
...
</configuration>

I also followed Dai's recommendation to try precompiling views. This is done by editing the MVC project's .csproj file with:

<MvcBuildViews>true</MvcBuildViews>

Precompiling the views is not necessary, but did prove it was indeed views compiling differently than the main project, and made it a tiny bit faster to test because I didn't have to run the site to see it blow up.

这篇关于如何在编译时或为ASP.NET视图编译时引用强命名的DLL?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆