-
Notifications
You must be signed in to change notification settings - Fork 252
PackageTargetFallback (new design for Imports)
https://docs.nuget.org/ndocs/schema/msbuild-targets#packagetargetfallback
Sometimes, when attempting to use a package, the package doesn't have the appropriate TargetFramework supported. Imports provided a way for you to specify, for that case, which TargetFramework's assets to use instead - since you know they are compatible.
From: https://docs.nuget.org/ndocs/schema/project.json
Imports Imports are designed to allow packages that use the dotnet TxM to operate with packages that don't declare a dotnet TxM. If your project is using the dotnet TxM then all the packages you depend on must also have a dotnet TxM, unless you add the following to your project.json in order to allow non dotnet platforms to be compatible with dotnet. If you are using the dotnet TxM then the PCL project system will add the appropriate imports statement based on the supported targets.
"frameworks": { "dotnet": { "imports" : "portable-net45+win81" } }
Developers who are consuming NuGet packages.
<PackageTargetFallback Condition="'$(TargetFramework)'=='Net45'">portable-net45+win81</PackageTargetFallback>
PackageTargetFallbacks may have been set in one of Microsoft targets (we are considering), or other ones. If you'd like to add the list already provided, you can add additional values to the PackageTargetFallback property:
<PackageTargetFallback Condition="'$(TargetFramework)'=='Net45'">
$(PackageTargetFallback);portable-net45+win8+wpa81+wp8
</PackageTargetFallback >
If a restore is bringing the wrong assembly, it is possible to exclude that packages default choice, and replace it with your own choice. First with a top level packagereference, exclude all assets:
<PackageReference Include="Newtonsoft.Json" Version="9.0.1">
<ExcludeAssets>All</ExcludeAssets>
</PackageReference>
Next, add your own reference to the appropriate local copy of the dll:
<Reference Include="Newtonsoft.Json.dll" />
- We need to confirm that NuGet code already knows all the guaranteed compatible TFMs - review with Eric St. John, and others.
- After we've confirmed our code is complete, we should consider adding some PackageTargetFallbacks into Microsoft targets as well.
- Will we create any UI in VS to expose the fact that PackageTargetFallbacks are used/specified: no
- We should ensure that NuGet logging output includes the fact that a PackageTargetFallback was used, since no compatible TFM was found.
Check out the proposals in the accepted
& proposed
folders on the repository, and active PRs for proposals being discussed today.