建立自己的错误和QUOT;是否缺少using指令或程序集引用" - 目标框架版本4 [英] Build error "Are you missing a using directive or assembly reference" - target framework version 4
问题描述
我有一个使用库(从的NuGet)项目
目标框架为我的项目是目前4.0
我使用的对象和方法从库中,我得到智能感知等...
然而,当我建,编译失败与
类型或命名空间无法找到。是否缺少using指令或程序集引用?
如果我更改项目4.5的目标框架,它编译。</ P>
有没有办法解决这?
修改
作为具体的例子,这里的步骤,以在一个特定的情况下,重现了这一问题。
- 文件 - >新建项目
- 在新的控制台应用程序
-
设置目标框架,4.0
-
的NuGet安装 paymill包装
使用的一种类型,在Paymill包装。例如:
使用PaymillWrapper.Models;
使用PaymillWrapper.Service;
公共类MyClass的
{
私人只读PaymentService _paymentService;
}
VS不抱怨。
编译
接收错误:
的类型或命名空间名称ClientService'找不到(是否缺少using指令或程序集引用?)
答案在于构建输出:
2> C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ Microsoft.Common.targets(1605,5):警告MSB3274:主要参考PaymillWrapper无法得到解决,因为它是建立对.NETFramework,版本= V4.5的框架。这是一个更高的版本比当前目标框架.NETFramework,版本= 4.0版。
2> C:\ WINDOWS \ Microsoft.NET \框架\ v4.0.30319 \ Microsoft.Common.targets(1605,5):警告MSB3268:主要参考PaymillWrapper无法得到解决,因为它有一个间接的依赖在框架组装System.Net.Http,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a,它无法在当前的目标框架内解决。 .NETFramework,版本= V4.0。要解决此问题,要么删除提及PaymillWrapper或重新定位你的应用程序的框架版本,其中包含System.Net.Http,版本= 4.0.0.0,文化=中性公钥= b03f5f7f11d50a3a。
在换句话说,的NuGet包使用的引用,.NET 4.5,所以你只能用它在.NET 4.5 +项目。
您可能要问Paymill包装的作者,看看他们是否能公布其面向.NET 4,而不是一个版本。
请注意,的NuGet包页面连州这样的:
依赖
- .NETFramework 4.5
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
The type or namespace could not be found. Are you missing a using directive or assembly reference?
If I change the target framework of the project to 4.5, it compiles.
Is there a way round this?
EDIT
As a specific example, here are the steps to reproduce this problem in one particular case.
- File -> New Project
- New Console application
Set Target framework to 4.0
Nuget install paymill wrapper
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 doesn't complain.
Compile
Receive error:
The type or namespace name 'ClientService' could not be found (are you missing a using directive or an assembly reference?)
The answer lies in the build output:
2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.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:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.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".
In other words, the NuGet package uses a reference to .NET 4.5, so you can only use it on .NET 4.5+ projects.
You might want to ask the authors of Paymill Wrapper to see if they could publish a version which targets .NET 4 instead.
Note that the NuGet package page even states this:
Dependencies
- .NETFramework 4.5
这篇关于建立自己的错误和QUOT;是否缺少using指令或程序集引用&QUOT; - 目标框架版本4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!