GoCardless SDK "requires a later version of the .NET Framework than the one specified in the project"(ASP.NET 3.5,Visual Studio 2010)

GoCardless SDK "requires a later version of the .NET Framework than the one specified in the project" (ASP.NET 3.5, Visual Studio 2010)

更新 201521011559:我想知道这是否是由用于构建包的 .nuspec 文件中的依赖项规范错误引起的...

客户端 SDK 的 .nuspec 文件位于 GoCardless 的 GitHub 存储库中

https://github.com/gocardless/gocardless-dotnet/blob/master/GoCardlessSdk/GoCardlessSdk.nuspec

并包括此部分:

<dependencies>
  <group targetFramework="net20">
    <dependency id="Newtonsoft.Json" version="4.5.11"/>
    <dependency id="RestSharp.Net2" version="1.1.11"/>
  </group>

  <!-- For reasons unknown, NuGet pack will not recognise targetFramework and tries to put all our deps into the default group.-->
  <!--
  <group targetFramework="net35">
    <dependency id="Newtonsoft.Json" version="5.0.2"/>
    <dependency id="RestSharp" version="104.1"/>
  </group>
  -->
</dependencies>

我的想法是否正确,这意味着无论目标项目的目标框架版本如何,它都会尝试安装 RestSharp.Net2?


原始问题:

我们的一个项目是 ASP.NET Web 应用程序 - 目标框架设置为 .NET 3.5,没有客户端配置文件或任何东西。

我刚刚安装了包含 GoCardless .NET SDK 的 NuGet 包 (http://www.nuget.org/packages/GoCardless/)

PM> Install-Package GoCardless

它似乎工作正常。然后我在我的一个页面中添加了对 GoCardless.Sdk 的引用,项目拒绝编译:

The type or namespace name 'GoCardlessSdk' could not be found (are you missing a using directive or an assembly reference?)

真正 奇怪的是,如果我删除引用,然后 right-click 引用,添加引用,浏览到 ..\packages\GoCardless\lib\net35\ 文件夹和 select GoCardlessSdk.dll,我得到这个错误:

'GoCardlessSdk.dll', or one of its dependencies, requires a later version of the .NET Framework than the one specified in the project. You can change the .NET Framework target by clicking Properties on the Project menu and then selecting a new target in the '.NET Framework' dropdown box.

Do you still want to add a reference to 'GoCardlessSdk.dll' in the project?

我已经使用 NuGet 包资源管理器检查了包。它肯定公开了 .NET 2.0 和 .NET 3.5 版本;唯一的依赖项是 Newtonsoft.Json 和 RestSharp,两者 运行 在 .NET 3.5 上都很好。

我在 Windows 7 x64 上使用 Visual Studio 2010 Premium。这是 Visual Studio 问题、.NET 问题还是 GoCardless SDK NuGet 程序包有什么特别的问题?

我建议您重新安排整个解决方案:

首先删除:- GoCardless 客户端库 1.1.15(或 1.1.16) 如果您现在已经安装了它,请再次:

然后尝试再次编译您的解决方案,如果一切运行正常,您应该会收到无法从引用 .dll 中找到文件的错误,对吗?

你需要确保:

.NETFramework 3.5

Newtonsoft.Json (≥ 5.0.2) || RestSharp (≥ 104.1) and for

Or for .NETFramework 2.0

Newtonsoft.Json (≥ 4.5.11) || RestSharp.Net2 (≥ 1.1.11)

与此处的版本完全匹配。 (来自 GoCardless 的最新更新)

如果您已使用 nuget 控制器检查过:

Updating a Package(click to visit page)

From the Tools menu, select Library Package Manager and then click Package Manager Console. To check if there are newer versions available for any installed packages, enter Get-Package -updates at the prompt.

Get-Package command

To update a package, enter Update-Package with the package ID. For example, enter the command Update-Package jQuery. For more options that you can use with the Update-Package command, enter get-help Update-Package or see (../Reference/Package-manager-Console-Commands).

如果完成这些更新/降级,您可以通过 doing following:

更改应用程序的 .Net Framework
  1. In Solution Explorer, open the shortcut menu for the project that you want to change, and then choose Properties.

  2. In the left column of the properties window, choose the Application tab. Visual Studio App Properties Application tab

(After you create a Windows Store app in Visual Studio 2013, you can't change the targeted version of either Windows or the .NET Framework.)

  1. In the Target Framework list, choose the version that you want.

  2. In the verification dialog box that appears, choose the Yes button.

The project unloads. When it reloads, it targets the .NET Framework version that you just chose.

如果您已将其更改为 .Net FrameWork 3.5(我建议您考虑导入),您可以重新导入 GoCardless.dll 并告诉我发生了什么。在我看来,它应该能够添加引用并开始使用它。

我过去通过卸载 Microsoft Blend 解决了这个问题。它与 Visual Studio 2012 一起安装,并且还会安装自己的 Newtonsoft.Json.dll 版本。它对 DLL 做了一些奇怪的事情(也许它在 GAC 中安装了 DLL?)导致 Visual Studio 引用 DLL 的 Blend 版本,而不是它应该引用的任何其他 DLL。

可能有比卸载 Microsoft Blend 更友好的解决方案,但如果您不使用 Blend,那么这是最简单的选择!

该包不再受支持并且已被其所有者取消列出。

我在这里创建了一个新的:

https://github.com/getAddress/goCardless

(或 PM> 安装包 getAddress.goCardless)