从 .Net 4.0 到 4.5 的重定向解决方案 - 如何重定向 NuGet 包? [英] Retargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?

查看:28
本文介绍了从 .Net 4.0 到 4.5 的重定向解决方案 - 如何重定向 NuGet 包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将当前在 VS2010 中针对 .NET 4.0 的解决方案迁移到 VS2012,现在我想将其重新定位到 .Net 4.5

I have migrated a solution that is currently targeting .NET 4.0 in VS2010 to VS2012 and now I would like to re-target it to .Net 4.5

我不确定的是 NuGet 包.例如,我在 VS2010 中从 EF4 更新的 EF5 实际上是 EF 4.4,正如您在此处看到的:

What I am not sure about is the NuGet packages. For example EF5, which I updated from EF4 in VS2010 turns out to be actually EF 4.4 as you can see here:

    <Reference Include="EntityFramework, Version=4.4.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..packagesEntityFramework.5.0.0lib
et40EntityFramework.dll</HintPath>
    </Reference>

我还可以在项目的packages.config 中看到以下内容:

I can also see the following in packages.config for the project:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="5.0.0" targetFramework="net40" />
</packages>

所以我的问题是:

将当前设置为面向 .NET 4.0 的所有 NuGet 包重新定位到面向 .NET 4.5 的最佳实践是什么?

What is the best practice to re-target all NuGet packages that are currently set to target .NET 4.0 to target .NET 4.5?

推荐答案

NuGet 2.1 提供了一个让这件事变得更简单的功能:只需执行 update-package -reinstall -ignoreDependencies来自包管理器控制台.

NuGet 2.1 offers a feature that makes this a lot simpler: just do update-package -reinstall -ignoreDependencies from the Package Manager Console.

NuGet 2.0 不能很好地处理重新定位您的应用程序.为了更改包的目标框架,您必须卸载并重新安装包(记下您已安装的包,以便您可以重新安装每个包).

NuGet 2.0 doesn't handle re-targeting your applications very well. In order to change your packages' target frameworks, you must uninstall and reinstall the packages (taking note of the packages you had installed so that you can reinstall each of them).

必须卸载并重新安装软件包的原因是:

The reason packages must be uninstalled and reinstalled is:

  • 在安装包时,我们会确定您项目的目标框架
  • 然后我们将其与包内容进行匹配,找到适当的 lib 文件夹(和 content 文件夹)
  • 程序集引用添加了指向包的 lib 文件夹的提示路径,带有正确的子文件夹(例如 lib et40)
  • 内容文件是从包content文件夹中复制的,带有正确的子文件夹(例如content et40)
  • 我们在packages.config文件中记录了用于安装包的targetFramework
  • 更改项目的目标框架后,提示路径仍指向 net40
  • 当您卸载软件包时,我们会检查在 packages.config 中记录的 targetFramework,以查看要从您的项目中删除哪些目标框架的库/内容
  • 当您重新安装软件包时,我们会检测您更新的目标框架并引用/复制正确的库/内容
  • When installing a package, we determine the target framework of your project
  • We then match that up with the package contents, finding the appropriate lib folder (and content folder)
  • Assembly references are added with Hint Paths that point to the package's lib folder, with the right subfolder (lib et40 for example)
  • Content files are copied from the packages content folder, with the right subfolder (content et40 for example)
  • We record the targetFramework used to install the package within the packages.config file
  • After you change your project's target framework, the Hint Paths still point to net40
  • When you uninstall packages, we check the targetFramework that was recorded in packages.config to see what target framework's libs/content to remove from your project
  • When you reinstall the package, we detect your updated target framework and reference/copy the right libs/content

这篇关于从 .Net 4.0 到 4.5 的重定向解决方案 - 如何重定向 NuGet 包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆