.net 当我添加对 MEF 插件项目的引用时,为什么会出现警告图标?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20186216/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Why do I get a warning icon when I add a reference to an MEF plugin project?
提问by ProfK
I wish to test the core class of a plugin by directly referencing the plugin project and instantiating the plugin class. When I create a test Console App project and add a project reference to the plugin project, I get a warning icon (yellow triangle with exclamation mark) next to the reference in the References list.
我希望通过直接引用插件项目并实例化插件类来测试插件的核心类。当我创建一个测试控制台应用程序项目并向插件项目添加项目引用时,我在“引用”列表中的引用旁边看到一个警告图标(带有感叹号的黄色三角形)。
When I instead add a reference to the dll, the assembly build output of the plugin, I get no such warning. What could this warning be trying to tell me?
当我改为添加对 dll 的引用(插件的程序集构建输出)时,我没有收到此类警告。这个警告想告诉我什么?
回答by kad81
As mentioned in the question's comments, differing .NET Framework versions between the projects can cause this. Check your new project's properties to ensure that a different default version isn't being used.
正如问题的评论中所提到的,项目之间不同的 .NET Framework 版本可能会导致这种情况。检查新项目的属性以确保未使用不同的默认版本。
回答by kbarry
Encountered the same issue with a ASP.Net Web App and two library class projects which needed to be referenced within the Web App. I had no information provided on why the build failed and the references were invalid.
ASP.Net Web App 和两个需要在 Web App 中引用的库类项目遇到了同样的问题。我没有提供有关构建失败和引用无效的原因的信息。
Solution was to ensure all projects had the same Target Framework:
解决方案是确保所有项目具有相同的目标框架:
In Visual Studio 2015- Right Click project > Properties > Application > Target Framework
在 Visual Studio 2015 中 -右键单击项目 > 属性 > 应用程序 > 目标框架
Save, Clean and Rebuild solution. The project references should no longer appear as yellow warnings and the solution will compile.
保存、清理和重建解决方案。项目引用不应再显示为黄色警告,解决方案将编译。
My Web App was targeting .Net 4.5 whereas the other two dependent library class projects targeted .Net v4.5.2
我的 Web 应用程序的目标是 .Net 4.5,而其他两个依赖库类项目的目标是 .Net v4.5.2
回答by user3578181
For both of (or all of) the projects that you want to use together:
对于要一起使用的两个(或全部)项目:
Right click on the project > Properties > Application > Target .NET framework
右键单击项目 > 属性 > 应用程序 > 目标 .NET 框架
Make sure that both of (or all of) your projects are using the same .NET framework version.
确保您的两个(或所有)项目都使用相同的 .NET 框架版本。
回答by Aljohn Yamaro
- Make sure all versions are same for each projectsclick each projects and see the version here Project > Properties > Application > Target .NET framework
a. Go to Tools > Nuget Package Manager > Package Manager Console Type Update-Package -Reinstall(if not working proceed to 2.b)
b. THIS IS CRITICAL BUT THE BIGGEST POSSIBILITY THAT WILL WORK. Remove < Target > Maybe with multiple lines< /Target >usually found at the bottom part of .csproj.
Save, load and build the solution.
- 确保每个项目的所有版本都相同单击每个项目并在此处查看版本 Project > Properties > Application > Target .NET framework
一种。转到工具 > Nuget 包管理器 > 包管理器控制台类型Update-Package -Reinstall(如果不工作,请继续2.b)
湾 这是至关重要的,但最大的可能性是可行的。删除 <Target>可能带有多行</Target>通常在 .csproj 的底部找到。
保存、加载和构建解决方案。
回答by Nitin Badole
Reinstall all packages in all projects of the current solution:
重新安装当前解决方案的所有项目中的所有包:
Update-Package -Reinstall
回答by user274294
Make sure you have the projects targeting the same framework version. Most of the times the reason would be that current project ( where you are adding reference of another project ) points to a different .net framework version than the rest ones.
确保您的项目面向相同的框架版本。大多数情况下,原因是当前项目(在其中添加另一个项目的引用)指向与其余项目不同的 .net 框架版本。
回答by Justin
For me, I ran into this issue when referencing a .NET Standard 2.0 class library in a .NET Framework 4.7.1 console application. Yes, the frameworks are different, but they are compatible (.NET Standard is supposed to jive with both .NET Core and .NET Framework.) I tried cleaning, rebuilding, removing and readding the project reference, etc... with no success. Finally, quitting Visual Studio and reopening resolved the issue.
对我来说,我在 .NET Framework 4.7.1 控制台应用程序中引用 .NET Standard 2.0 类库时遇到了这个问题。是的,框架是不同的,但它们是兼容的(.NET Standard 应该与 .NET Core 和 .NET Framework 兼容。)我尝试清理、重建、删除和阅读项目引用等......但没有成功. 最后,退出 Visual Studio 并重新打开解决了该问题。
回答by Sumit khare
Check NETFramework of the referred dll & the Project where you are adding the DLL. Ex: DLL ==> supportedRuntime version="v4.0" Project ==> supportedRuntime version="v3.0"
检查引用的 dll 的 NETFramework 和添加 DLL 的项目。例如:DLL ==> supportedRuntime version="v4.0" Project ==> supportedRuntime version="v3.0"
You will get warning icon. Solution : Make dll version consistence across.
你会得到警告图标。解决方案:使 dll 版本保持一致。
回答by HappyTown
It's been a long time since this question was asked but if someone is still interested - I recently ran into similar icons. I was compiling a C#.net project using VS 2008. I found VS could not locate the assemblies for those references. When I double clicked VS refreshed the references and removed the icons on some of those[EDIT: which it could NOW locate]. For remaining references, I had to compile the respective assemblies.
自从问这个问题已经很长时间了,但如果有人仍然感兴趣 - 我最近遇到了类似的图标。我正在使用 VS 2008 编译 C#.net 项目。我发现 VS 无法找到这些引用的程序集。当我双击 VS 时,刷新了引用并删除了其中一些[编辑:现在可以找到] 上的图标。对于剩余的引用,我必须编译相应的程序集。
回答by JenonD
Adding my 2 cents to the @kad81 answer,
将我的 2 美分加到@kad81 的答案中,
Go to Visual Studio -> BUILD -> Configuration Manager
转到 Visual Studio -> BUILD -> 配置管理器
In the "Active Solution Platform" drop down in top right hand corner (mine is VS 2012), if it is "Mixed Platforms", change it to the appropriate platform based upon your reference third party assemblies.
在右上角的“活动解决方案平台”下拉菜单中(我的是 VS 2012),如果它是“混合平台”,请根据您参考的第三方程序集将其更改为适当的平台。
Then in each of the project in the list, make sure you select same platform for all the project. (if x86 not exist, then select "", then you can select "x86".)
然后在列表中的每个项目中,确保为所有项目选择相同的平台。(如果 x86 不存在,则选择“”,则可以选择“x86”。)
Rebuild the library projects first and then referencing projects. Hope this helps.
先重建库项目,然后再引用项目。希望这可以帮助。

