尝试添加一个强类型的观点并没有发现在MVC项目中的所有类 [英] Attempting to add a strongly typed view does not find any classes in the MVC project

查看:156
本文介绍了尝试添加一个强类型的观点并没有发现在MVC项目中的所有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个很奇怪的问题。每当我尝试使用ASP.NET MVC2添加视图对话框,然后尝试通过选择从下拉一个查看数据类可用类的类都(模式下创建一个强类型的视图 )在我的MVC项目被显示出来。

I have a very odd problem. Whenever I try to use the "Add View" dialog in ASP.NET MVC2 and then try to "Create a strongly-typed view" by selecting a "View data class" from the drop down of available classes none of the classes ("models") in my MVC project are showing up.

很奇怪的部分是所有我的MVC项目被引用,甚至其他项目的解决方案中的组件,它们的类显示出来。我曾尝试清洗,改造,清理OBJ文件夹,但每一次的没有在我的实际MVC组件类的某些原因被显示出来。这是工作之前罚款,但现在它已不,我真的不能相信任何东西都改变了。

The very odd part is all of the assemblies that my MVC project is referencing, even other projects in the solution, their classes are showing up. I have tried cleaning, rebuilding, cleaning the obj folder but every single time for some reason none of the classes in my actual MVC assembly are showing up. It was working fine before but now it doesn't anymore and I can't really think of anything that has changed.

任何人都经历过这个问题之前?
感谢您的帮助!

Anyone experienced this issue before? Thanks for the help!

例如图像:

推荐答案

想通了这一点,这里是解决方案:

Figured this out, here is the solution:

在MVC项目中引用了一堆服务合同组件,凡引用CommonServiceContractAssembly.dll。该MVC项目还引用CommonServiceContractAssembly.dll。 MVC的项目和服务合同组件均建引用略有不同版本的CommonServiceContractAssembly.dll

The MVC Project was referencing a bunch of service contract assemblies that where referencing a "CommonServiceContractAssembly.dll". The MVC Project was also referencing "CommonServiceContractAssembly.dll". The MVC Project and the service contract assemblies were all built referencing slightly different versions of "CommonServiceContractAssembly.dll"

在Visual Studio 2010中反映了所有引用的程序集,以创建一个强类型的视图我认为这是不知道如何处理略有不同版本CommonServiceContractAssembly.dll被引用所以也没显示反映了强类型模型对任何组件依赖于CommonServiceContractAssembly.dll。

When Visual Studio 2010 was reflecting on all referenced assemblies to "Create a strongly-typed view" of I believe it wasn't sure how to handle the slightly different version of "CommonServiceContractAssembly.dll" being referenced so it didn't display the reflected "strongly typed model" possibilities for any assemblies dependent on "CommonServiceContractAssembly.dll".

解决方法是强制实际Visual Studio 2010中的应用程序域时,Visual Studio 2010的启动用CommonServiceContractAssembly.dll的正确版本。这是一个完成后生成事件这样的:

The fix is to actually force Visual Studio 2010's app domain to use the correct version of "CommonServiceContractAssembly.dll" when Visual Studio 2010 starts up. This was accomplished with a Post Build Event like the following:

REM这是必需的T4代车型从正常工作
复制$(TARGETDIR)CommonServiceContractAssembly.dll$(DevEnvDir)PublicAssemblies \\/ Y

REM This is required for T4 generation from models to work properly copy "$(TargetDir)"CommonServiceContractAssembly.dll" "$(DevEnvDir)PublicAssemblies\" /Y

所以我复制引用遍地开花到哪里Visual Studio会加载CommonServiceContractAssembly.dll。我做了这个后一切工作正常。

So I copy "CommonServiceContractAssembly.dll" that is referenced "everywhere" into where Visual Studio will load it. After I did this everything worked properly.

另一种选择是要始终确保具有共同依赖的所有组件总是以同样的版本的依赖编译。

Another option would be to always ensure that all assemblies that share a common dependency are always compiled with the same version of that dependency.

这篇关于尝试添加一个强类型的观点并没有发现在MVC项目中的所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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