コード例 #1
0
        public async Task InstallPackageAsync(
            PackageViewModel packageViewModel,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var package = new InteractivePackage(packageViewModel.Package);

            var installedPackages = await Workbook.Packages.InstallPackageAsync(
                package,
                packageViewModel.SourceRepository,
                cancellationToken);

            // TODO: Should probably alert user that the package is already installed.
            //       Should we add a fresh #r for the package in case that's what they're trying to get?
            //       A feel good thing?
            if (installedPackages.Count == 0)
            {
                return;
            }

            foreach (var installedPackage in installedPackages)
            {
                ReferencePackageInWorkspace(installedPackage);
                await LoadPackageIntegrationsAsync(installedPackage, cancellationToken);
            }

            // TODO: Figure out metapackages. Install Microsoft.AspNet.SignalR, for example,
            //       and no #r submission gets generated, so all the workspace reference stuff
            //       above fails to bring in references to dependnet assemblies automatically.
            //       User must type them out themselves.
            //
            //       This was busted in our NuGet 2.x code as well.
            package = installedPackages.FirstOrDefault(
                p => PackageIdComparer.Equals(p, package));

            // TODO: Same issue as installedPackages.Count == 0. What do we want to tell user?
            //       probably they tried to install a package they already had installed, and
            //       maybe it bumped a shared dep (which is why installedPackages is non-empty).
            if (package == null)
            {
                return;
            }

            await ReferenceTopLevelPackageAsync(
                package,
                cancellationToken);
        }
コード例 #2
0
ファイル: NuGetTests.cs プロジェクト: pietervp/workbooks-1
        public async Task CanInstall(FrameworkName targetFramework, PackageInstallData data)
        {
            var project = CreatePackageManager(targetFramework);
            await project.InstallPackageAsync(
                new InteractivePackage (new PackageIdentity(data.Id, data.VersionToInstall)),
                sourceRepository : null, // use default
                cancellationToken : CancellationToken.None);

            var packages = project.InstalledPackages.Where(
                p => PackageIdComparer.Equals(p.Identity.Id, data.Id));

            packages.Count().ShouldEqual(1);

            var package = packages.Single();

            package.IsExplicit.ShouldBeTrue();
            package.Identity.Version.ShouldEqual(data.ExpectedInstalled);
            package.SupportedVersionRange.ShouldEqual(new VersionRange(data.ExpectedInstalled));
        }
コード例 #3
0
        public void TestPackageVersionRanges()
        {
            var packages = ReadWorkbookPage("ArbitraryYAMLManifest.workbook").Page.Packages;

            packages.Length.ShouldEqual(4);

            var expectedPackages = new [] {
                new { id = "Fake.Package1", originalRange = "9.0.1", normalizedRange = "[9.0.1, )" },
                new { id = "Fake.Package2", originalRange = "[9.0.1]", normalizedRange = "[9.0.1, 9.0.1]" },
                new { id = "Fake.Package3", originalRange = "9.0.*", normalizedRange = "[9.0.*, )" }, // TODO: Really? Was expecting something like [9.0, 9.1)
                new { id = "Fake.Package4", originalRange = "[9,10)", normalizedRange = "[9.0.0, 10.0.0)" },
            };

            foreach (var expected in expectedPackages)
            {
                var package = packages.Single(p => PackageIdComparer.Equals(p.Identity.Id, expected.id));
                package.SupportedVersionRange.OriginalString.ShouldEqual(expected.originalRange);
                package.SupportedVersionRange.ToNormalizedString().ShouldEqual(expected.normalizedRange);
            }
        }
コード例 #4
0
        IEnumerable <ExternalDependency> GetKestrelLibuvDependencies(FilePath path)
        {
            var packageDirectoryPath = path.ParentDirectory.ParentDirectory.ParentDirectory;

            // Get all the available libuv's
            var allPackagesPath   = packageDirectoryPath.ParentDirectory.ParentDirectory;
            var libuvPackagesPath = allPackagesPath.Combine("libuv");
            var libuvVersions     = libuvPackagesPath.EnumerateDirectories()
                                    .Select(dir => NuGetVersion.Parse(dir.Name))
                                    .ToArray();

            // Read the transport's nuspec to find the best matching version of libuv
            var nuspecPath = packageDirectoryPath.Combine(
                "microsoft.aspnetcore.server.kestrel.transport.libuv.nuspec");
            var nuspecData             = new NuspecReader(nuspecPath);
            var libuvDependencyVersion = nuspecData.GetDependencyGroups()
                                         .SelectMany(dg => dg.Packages)
                                         .Where(p => PackageIdComparer.Equals(p.Id, "Libuv"))
                                         .Distinct(PackageIdComparer.Default)
                                         .SingleOrDefault()
                                         ?.VersionRange
                                         .FindBestMatch(libuvVersions);

            var libuvPackagePath = libuvPackagesPath.Combine(libuvDependencyVersion.ToString());

            var isMac        = InteractiveInstallation.Default.IsMac;
            var architecture = Environment.Is64BitProcess && (isMac || AgentType != AgentType.DotNetCore)
                ? "x64"
                : "x86";

            string runtimeName, nativeLibName;

            switch (AgentType)
            {
            case AgentType.WPF:
                // We need the win7-<bitness> library here.
                nativeLibName = "libuv.dll";
                runtimeName   = $"win-{architecture}";
                break;

            case AgentType.Console:
            case AgentType.MacNet45:
            case AgentType.MacMobile:
            case AgentType.DotNetCore:
                nativeLibName = isMac ? "libuv.dylib" : "libuv.dll";
                runtimeName   = isMac ? "osx" : $"win-{architecture}";
                break;

            default:
                yield break;
            }

            var nativeLibraryPath = libuvPackagePath.Combine(
                "runtimes",
                runtimeName,
                "native",
                nativeLibName
                );

            if (nativeLibraryPath.FileExists)
            {
                yield return(new NativeDependency(nativeLibraryPath.Name, nativeLibraryPath));
            }
        }
コード例 #5
0
        async Task LoadPackageIntegrationsAsync(
            InteractivePackage package,
            CancellationToken cancellationToken)
        {
            // Forms is special-cased because we own it and load the extension from our framework.
            if (PackageIdComparer.Equals(package.Identity.Id, "Xamarin.Forms"))
            {
                await CompilationWorkspaceFactory.LoadFormsAgentExtensions(
                    package.Identity.Version.Version,
                    this,
                    CompilationWorkspace.DependencyResolver,
                    CompilationWorkspace.EvaluationContextId,
                    Agent.IncludePeImage);
            }

            var assembliesToLoadOnAgent = new List <ResolvedAssembly> ();

            // Integration assemblies are not expected to be in a TFM directory—we look for them in
            // the `xamarin.interactive` folder inside the NuGet package.
            var packagePath = Workbook
                              .Packages
                              .GetPackageInstallPath(package);

            var interactivePath = packagePath.Combine("xamarin.interactive");

            if (interactivePath.DirectoryExists)
            {
                var interactiveAssemblies = interactivePath.EnumerateFiles("*.dll");
                foreach (var interactiveReference in interactiveAssemblies)
                {
                    var resolvedAssembly = CompilationWorkspace
                                           .DependencyResolver
                                           .ResolveWithoutReferences(interactiveReference);

                    if (HasIntegration(resolvedAssembly))
                    {
                        assembliesToLoadOnAgent.Add(resolvedAssembly);

                        foreach (var dependency in resolvedAssembly.ExternalDependencies)
                        {
                            if (!(dependency is WebDependency))
                            {
                                continue;
                            }

                            if (AddNuGetWebResource(dependency.Location, out var id))
                            {
                                await WorkbookPageViewModel.LoadWorkbookDependencyAsync($"/static/{id}");
                            }
                        }
                    }
                }
            }

            if (assembliesToLoadOnAgent.Count > 0)
            {
                var assembliesToLoad = assembliesToLoadOnAgent.Select(dep => {
                    var peImage = Agent.IncludePeImage
                        ? GetFileBytes(dep.Path)
                        : null;
                    var syms = Agent.IncludePeImage
                        ? GetDebugSymbolsFromAssemblyPath(dep.Path)
                        : null;
                    return(new AssemblyDefinition(
                               dep.AssemblyName,
                               dep.Path,
                               peImage: peImage,
                               debugSymbols: syms
                               ));
                }).ToArray();

                await Agent.Api.LoadAssembliesAsync(
                    CompilationWorkspace.EvaluationContextId,
                    assembliesToLoad);
            }

            await RefreshForAgentIntegration();
        }