You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[Xamarin.Android.Build.Tasks] Better support for netstandard libraries.
Fixesdotnet#1154, dotnet#1162
Netstandard packages sometimes ship with both reference and
implementation assemblies. The Nuget build task `ResolveNuGetPackageAssets`
only resolves the `ref` version of the assemblies. There does
not seem to be away way to FORCE Nuget to resolve the lib one.
How .net Core manages to do this is still a mistery. That said
the Nuget `ResolveNuGetPackageAssets` does give us a hint as to
how to use the `project.assets.json` file to figure out what
`lib` version of the package we should be including.
This commit reworks `ResolveAssemblies` to attempt to map the
`ref` to a `lib` if we find a Referenece Assembly. Historically
we just issue a warning (which will probably be ignored), but
now we will use the `project.assets.json` file to find the
implementation version of the `ref` assembly.
We need to be using `NewtonSoft.Json` since it provides a decent
API for querying json. We make use of the Nuget build properties
`$(ProjectLockFile)` for the location of the `project.assets.json`
, `$(NuGetPackageRoot)` for the root folder of the Nuget packages
and `$(NuGetTargetMoniker)` and `$(_NuGetTargetFallbackMoniker)`
for resolving which `TargetFrameworks` we are looking for. All of these
properties should be set by Nuget. If they are not we should fallback
to the default behaviour and just issue the warning.
{
"version": 3,
"targets": {
"MonoAndroid,Version=v8.1": {
"System.IO.Packaging/4.4.0": {
"type": "package",
"compile": {
"ref/netstandard1.3/System.IO.Packaging.dll": {}
},
"runtime": {
"lib/netstandard1.3/System.IO.Packaging.dll": {}
}
},
}
}
}
The code above is a cut down sample of the `project.assets.json`. So our
code will first resolve the `targets`. We use `$(NuGetTargetMoniker)` to
do this. For an android project this should have a value of
`MonoAndroid,Version=v8.1`. Note we do NOT need to worry about the version
here. When Nuget restores the packages it creates the file so it will
use the correct version.
Next we try to find the `System.IO.Packaging/4.4.0`. My first throught
was to use the version of the reference assembly we just loaded. But
in this package even though the nuget version was `4.4.0` the assembly
versioin was `4.0.2` .. so not helpful. So we need to just search for the
items starting with `System.IO.Packaging`. Next is to look for the `runtime`
item and then finally the value of that. Once we have resolved the path
we need to then combine that with the `$(NuGetPackageRoot)` to get the
full path to the new library. If at any point during all of this code
we don't get what we expect (i.e a null) we should abort and just issue
the warning.
The only real concern with this is if the format of the `project.assets.json`
file changes. It is not ment to be edited by a human so there is the
possibiltity that the Nuget team will decide to either change the schema or
even migrate to a new file format.
0 commit comments