构建错误“您是否缺少 using 指令或程序集参考"- 目标框架版本 4 [英] Build error "Are you missing a using directive or assembly reference" - target framework version 4
问题描述
我有一个使用库的项目(来自 nuget)
我项目的目标框架目前是4.0
I've got a project that uses a library (from nuget)
The target framework for my project is currently 4.0
我正在使用库中的对象和方法,我获得了智能感知等...
I'm using objects and methods from the library, I get intellisense etc...
但是,当我构建时,编译失败
However, when I build, compilation fails with
找不到类型或命名空间.您是否缺少 using 指令或程序集引用?
The type or namespace could not be found. Are you missing a using directive or assembly reference?
如果我将项目的目标框架更改为 4.5,它会编译.
If I change the target framework of the project to 4.5, it compiles.
有没有办法解决这个问题?
Is there a way round this?
编辑
作为一个具体示例,以下是在一个特定情况下重现此问题的步骤.
As a specific example, here are the steps to reproduce this problem in one particular case.
- 文件 -> 新建项目
- 新的控制台应用程序
将目标框架设置为 4.0
- File -> New Project
- New Console application
Set Target framework to 4.0
Nuget 安装 paymill 包装器
使用 Paymill 包装器中的一种类型.例如:
Use one of the types in the Paymill wrapper. For example:
using PaymillWrapper.Models;
using PaymillWrapper.Service;
public class MyClass
{
private readonly PaymentService _paymentService;
}
VS 没有抱怨.
编译
VS doesn't complain.
Compile
接收错误:
找不到类型或命名空间名称ClientService"(您是否缺少 using 指令或程序集引用?)
The type or namespace name 'ClientService' could not be found (are you missing a using directive or an assembly reference?)
推荐答案
答案在于构建输出:
2>C:WindowsMicrosoft.NETFrameworkv4.0.30319Microsoft.Common.targets(1605,5):警告 MSB3274:无法解析主要引用PaymillWrapper",因为它是针对.NETFramework,Version=v4.5"框架.这是比当前目标框架.NETFramework,Version=v4.0"更高的版本.
2>C:WindowsMicrosoft.NETFrameworkv4.0.30319Microsoft.Common.targets(1605,5): warning MSB3274: The primary reference "PaymillWrapper" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.0".
2>C:WindowsMicrosoft.NETFrameworkv4.0.30319Microsoft.Common.targets(1605,5):警告 MSB3268:无法解析主要引用PaymillWrapper",因为它具有间接依赖关系在当前目标框架中无法解决的框架程序集System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"上..NETFramework,版本 = v4.0".要解决此问题,请删除引用PaymillWrapper"或将您的应用程序重定向到包含System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"的框架版本.
2>C:WindowsMicrosoft.NETFrameworkv4.0.30319Microsoft.Common.targets(1605,5): warning MSB3268: The primary reference "PaymillWrapper" could not be resolved because it has an indirect dependency on the framework assembly "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v4.0". To resolve this problem, either remove the reference "PaymillWrapper" or retarget your application to a framework version which contains "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
换句话说,NuGet 包使用对 .NET 4.5 的引用,因此您只能在 .NET 4.5+ 项目中使用它.
In other words, the NuGet package uses a reference to .NET 4.5, so you can only use it on .NET 4.5+ projects.
您可能想询问 Paymill Wrapper 的作者,看看他们是否可以发布针对 .NET 4 的版本.
You might want to ask the authors of Paymill Wrapper to see if they could publish a version which targets .NET 4 instead.
请注意,NuGet 包页面 甚至声明了这一点:
Note that the NuGet package page even states this:
依赖
- .NETFramework 4.5
Dependencies
- .NETFramework 4.5
这篇关于构建错误“您是否缺少 using 指令或程序集参考"- 目标框架版本 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!