我是一名 Java 开发人员,刚开始学习 C# 来开发几个项目。我很高兴看到我习惯使用的许多 Java 框架(log4j、ant、hibernate 等)都有它们的 .net 版本(log4net、nant、nhibernate)。
我刚刚创建了一个项目并尝试将 log4net 程序集引用放入其中,但我收到以下警告(随后是 4 个错误,提示无法识别 log4net 命名空间和类):
The referenced assembly "log4net"
could not be resolved because it has a
dependency on "System.Web,
Version=4.0.0.0, Culture=neutral,
PublicKeyToken=b03f5f7f11d50a3a" which
is not in the currently targeted
framework
".NETFramework,Version=v4.0,Profile=Client".
Please remove references to assemblies
not in the targeted framework or
consider retargeting your project.
我添加了对 System.Web.ApplicationServices
和 System.Web.Services
的引用,但它不起作用。对于解决此依赖性问题的任何帮助,我们将不胜感激。
谢谢
更新:
如果您仍然收到此错误,则说明您使用的是过时版本的 log4net,您应该考虑更新到 current version ,它不需要完整的 .NET 4.0 框架。感谢@Philippe感谢您在评论中指出这一点。
您的项目正在引用不包括 System.Web 的 .NET 4.0 客户端配置文件;您实际上需要引用完整框架。
参见 How To: Target a Specific .NET Framework Version or Profile在 MSDN 上获取指导。
- In Visual Studio, open the project you want to change.
- Right-click the project in Solution Explorer and then click Properties.
In the Project Designer, locate the Target Framework list, as follows.
- For Visual Basic projects, click the Compile tab and then click
Advanced Compile Options. The Target
Framework list is in the Advanced
Compiler Settings dialog box.
- For Visual C# projects, the Target Framework list is on the
Application tab of the Project
Designer. For more information, see
Application Page, Project Designer
(C#).
- For Visual F# projects, the Target Framework list is on the
Application tab of the Project
Designer.
In the Target Framework list, select the .NET Framework version or
profile that you want. When you click
OK, the project unloads and then
reloads in the integrated development
environment (IDE). The project now
targets the .NET Framework version
that you just selected.
可能还感兴趣的是 Troubleshooting .NET Framework Targeting Errors .