Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
215 views
in Technique[技术] by (71.8m points)

Retargeting solution from .Net 4.0 to 4.5 - how to retarget the NuGet packages?

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

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>

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>

So my question is:

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 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:

  • 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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...