Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Xamarin.Android.Build.Tasks] Better support for netstandard libraries. #1356

Merged
merged 8 commits into from
Mar 21, 2018

Commits on Mar 21, 2018

  1. [Xamarin.Android.Build.Tasks] Better support for netstandard libraries.

    Fixes dotnet#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 `Nuget.ProjectModel` since it an API for
    querying the `project.assets.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)` 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`. We need to look at the
    `lockFile.Libraries` to get information about the install path in the
    Nuget folder, and then `target.Libraries` to pick out the  `runtime`
    item.
    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. Hopefully we can just update the `Nuget`
    nuggets if that happens.
    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    536120c View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    df6c979 View commit details
    Browse the repository at this point in the history
  3. ff

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    098d861 View commit details
    Browse the repository at this point in the history
  4. Add NuGetLogger

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    4451917 View commit details
    Browse the repository at this point in the history
  5. Added Licence Info

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    5a93b85 View commit details
    Browse the repository at this point in the history
  6. Rework the NuGetLogger

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    26c3701 View commit details
    Browse the repository at this point in the history
  7. Rework Nuget Fix

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    b66647a View commit details
    Browse the repository at this point in the history
  8. Fixed error in csproj

    dellis1972 committed Mar 21, 2018
    Configuration menu
    Copy the full SHA
    b8ee9c3 View commit details
    Browse the repository at this point in the history