-1

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?)

4

2 回答 2

4

答案在于构建输出:

2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1605,5):警告 MSB3274:无法解析主要参考“PaymillWrapper”,因为它是针对“.NETFramework”构建的,版本=v4.5" 框架。这是比当前目标框架“.NETFramework,Version=v4.0”更高的版本。

2>C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.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”的框架版本。

换句话说,NuGet 包使用对 .NET 4.5 的引用,因此您只能在 .NET 4.5+ 项目中使用它。

您可能想询问 Paymill Wrapper 的作者,看看他们是否可以发布针对 .NET 4 的版本。

请注意,NuGet 包页面甚至声明了这一点:

依赖
项 - .NETFramework 4.5

于 2013-08-21T21:58:35.533 回答
0

根据 Jon Skeet 的回答,问题实际上在于有问题的图书馆。

它是针对 .net 4.5 构建的

我提交了一个修复此问题的请求请求。

于 2013-08-21T23:23:46.090 回答