当前位置: 首页>>代码示例>>C#>>正文


C# DefaultPackagePathResolver.GetInstallPath方法代码示例

本文整理汇总了C#中DefaultPackagePathResolver.GetInstallPath方法的典型用法代码示例。如果您正苦于以下问题:C# DefaultPackagePathResolver.GetInstallPath方法的具体用法?C# DefaultPackagePathResolver.GetInstallPath怎么用?C# DefaultPackagePathResolver.GetInstallPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DefaultPackagePathResolver的用法示例。


在下文中一共展示了DefaultPackagePathResolver.GetInstallPath方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: IsPackageInstalled

        /// <summary>
        /// Checks whether an IPackage exists within a PackageManager.  By default, will use the UseSideBySide settings of the DefaultPackagePathProvider the PackageManager is instantiated with.
        /// If passed in TRUE for exhaustive, will check both with and without UseSideBySide set.
        /// </summary>
        /// <param name="packageManager"></param>
        /// <param name="package"></param>
        /// <param name="exhaustive"></param>
        /// <returns></returns>
        public static bool IsPackageInstalled(this PackageManager packageManager,  IPackage package, bool exhaustive = false)
        {

            var pathsDictionary = new Dictionary<string, bool>();
            //Oh god oh god. The <center> cannot hold it is too late.
            var useSideBySide = packageManager.PathResolver.GetPrivateField<bool>("_useSideBySidePaths");
            pathsDictionary.Add(Path.Combine(packageManager.PathResolver.GetInstallPath(package), 
                packageManager.PathResolver.GetPackageFileName(package.Id, package.Version)), useSideBySide);

            //We need to also check the inverse, to see if it was installed with the other setting....
            if (exhaustive)
            {
                var inversePathResolver = new DefaultPackagePathResolver(packageManager.PathResolver.GetPrivateField<IFileSystem>("_fileSystem"), !useSideBySide);
                pathsDictionary.Add(Path.Combine(inversePathResolver.GetInstallPath(package), inversePathResolver.GetPackageFileName(package.Id, package.Version)), !useSideBySide);
            }

            foreach (var path in pathsDictionary.Where(path => packageManager.FileSystem.FileExists(path.Key)))
            {
                if (path.Value)
                {
                    return true;
                }
                
                //If not useSideBySide, we need to crack open the zip file.
                //Need to crack the package open at this point and check the version, otherwise we just need to download it regardless
                var zipPackage = new ZipPackage(packageManager.FileSystem.OpenFile(path.Key));
                if (zipPackage.Version == package.Version)
                {
                    return true;
                }
            }

            //Its not here.  Really.  We tried.
            return false;
        }
开发者ID:modulexcite,项目名称:NuGet.Extras,代码行数:43,代码来源:IPackageManagerExtensions.cs

示例2: GetInstallPathPrependsFileSystemRootToPackageDirectory

        public void GetInstallPathPrependsFileSystemRootToPackageDirectory()
        {
            // Arrange
            MockFileSystem fs = new MockFileSystem();
            DefaultPackagePathResolver resolver = new DefaultPackagePathResolver(fs);
            IPackage testPackage = PackageUtility.CreatePackage("Test");

            // Act
            string installPath = resolver.GetInstallPath(testPackage);

            // Assert
            Assert.Equal(fs.Root + "Test.1.0", installPath);
        }
开发者ID:OsirisTerje,项目名称:sonarlint-vs,代码行数:13,代码来源:DefaultPackagePathResolverTest.cs

示例3: CanDetermineVersionlessPackageIsInstalled

        public bool CanDetermineVersionlessPackageIsInstalled(string id, string onDiskVersion, string packageVersion, bool installedUsingMultipleVersion, bool currentlyAllowMultipleVersions, bool exhaustive)
        {
            var mfs = new Mock<MockFileSystem>() { CallBase = true };
            mfs.Setup(m => m.Root).Returns(@"c:\packages");

            var installPathResolver = new DefaultPackagePathResolver(mfs.Object, installedUsingMultipleVersion);
            var currentPathResolver = new DefaultPackagePathResolver(mfs.Object, currentlyAllowMultipleVersions);

            var testPackage = new DataServicePackage()
            {
                Version = packageVersion,
                Id = id
            };

            var filePackage = new DataServicePackage()
            {
                Version = onDiskVersion,
                Id = id
            };

            IPackage zipPackage = null;
            if (!string.IsNullOrEmpty(onDiskVersion))
            {
                string baseLocation = installPathResolver.GetInstallPath(filePackage);
                string fileName = installPathResolver.GetPackageFileName(filePackage.Id, SemanticVersion.Parse(filePackage.Version));
                string filePath = Path.Combine(baseLocation, fileName);
                zipPackage = PackageUtility.GetZipPackage(filePackage.Id, filePackage.Version);
                mfs.Setup(m => m.FileExists(filePath)).Returns(true);
                mfs.Setup(m => m.OpenFile(filePath)).Returns(zipPackage.GetStream());
                mfs.Object.AddFile(filePath, zipPackage.GetStream());
            }

            var pm = new PackageManager(new MockPackageRepository(), currentPathResolver, mfs.Object);
            var exists = pm.IsPackageInstalled(testPackage,exhaustive: exhaustive);
            //var test = testPackage.IsPackageInstalled(allowMultipleVersions, pm, mfs.Object);
            return exists;
        }
开发者ID:modulexcite,项目名称:NuGet.Extras,代码行数:37,代码来源:IPackageManagerExtensionsTests.cs


注:本文中的DefaultPackagePathResolver.GetInstallPath方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。