Ejemplo n.º 1
0
        protected override void ExecuteCore()
        {
            if (Items != null)
            {
                NuGetPackageResolver packageResolver = NuGetPackageResolver.CreateResolver(PackageFolders, ProjectPath);

                var updatedItems = new List <ITaskItem>();

                foreach (var item in Items)
                {
                    string packageName    = item.GetMetadata(MetadataKeys.PackageName);
                    string packageVersion = item.GetMetadata(MetadataKeys.PackageVersion);
                    if (!string.IsNullOrEmpty(packageName) && !string.IsNullOrEmpty(packageVersion) &&
                        string.IsNullOrEmpty(item.GetMetadata(MetadataKeys.PackageDirectory)))
                    {
                        var newItem = new TaskItem(item);

                        //  Gracefully handle case where we don't have a packageResolver because we don't have an assets
                        //  file, which happens for design-time builds
                        if (packageResolver != null)
                        {
                            var parsedPackageVersion = NuGetVersion.Parse(packageVersion);

                            string packageDirectory = packageResolver.GetPackageDirectory(packageName, parsedPackageVersion);

                            newItem.SetMetadata(MetadataKeys.PackageDirectory, packageDirectory);
                        }

                        updatedItems.Add(newItem);
                    }
                    else
                    {
                        updatedItems.Add(item);
                    }
                }

                Output = updatedItems.ToArray();
            }
        }
Ejemplo n.º 2
0
        private string ResolvePackageAssetPath(LockFileTargetLibrary package, string relativePath)
        {
            string packagePath = _packageResolver.GetPackageDirectory(package.Name, package.Version);

            return(Path.Combine(packagePath, NormalizeRelativePath(relativePath)));
        }