Esempio n. 1
0
        public void CheckFramework()
        {
            var p  = new NugetPackage("Unity.Container", "5.11.10", "net472", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath());
            var ex = Assert.Throws <Exceptions.PackageInstallationException>(() => NugetHelper.InstallPackages(new[] { p }, false, null));

            Assert.IsInstanceOf <Exceptions.TargetFrameworkNotFoundException>(ex.InnerException.InnerException);
        }
Esempio n. 2
0
        [TestCase("CommonServiceLocator", "1.3", "portable-net4+sl5+netcore45+wpa81+wp8", "https://api.nuget.org/v3/index.json")] //Short version format.
        public void InstallPackage(string id, string version, string target, string source)
        {
            var p         = new NugetPackage(id, version, target, source, null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath());
            var installed = NugetHelper.InstallPackages(new[] { p }, false, null);

            Assert.AreEqual(1, installed.Count(), "Invalid number of installed packages");
        }
Esempio n. 3
0
        /// <summary>
        /// Saves the packages.config file and populates it with given installed NugetPackages.
        /// </summary>
        /// <param name="filepath">The filepath to where this packages.config will be saved.</param>
        public void Save(string filepath)
        {
            Packages.Sort(delegate(NugetPackageIdentifier x, NugetPackageIdentifier y)
            {
                if (x.Id == null && y.Id == null)
                {
                    return(0);
                }

                if (x.Id == null)
                {
                    return(-1);
                }

                if (y.Id == null)
                {
                    return(1);
                }

                return(x.Id == y.Id
                    ? string.Compare(x.Version, y.Version, StringComparison.Ordinal)
                    : string.Compare(x.Id, y.Id, StringComparison.Ordinal));
            });

            XDocument packagesFile = new XDocument();

            packagesFile.Add(new XElement("packages"));
            foreach (NugetPackageIdentifier package in Packages)
            {
                XElement packageElement = new XElement("package");
                packageElement.Add(new XAttribute("id", package.Id));
                packageElement.Add(new XAttribute("version", package.Version));
                packagesFile.Root?.Add(packageElement);
            }

            // remove the read only flag on the file, if there is one.
            bool packageExists = File.Exists(filepath);

            if (packageExists)
            {
                FileAttributes attributes = File.GetAttributes(filepath);

                if ((attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly)
                {
                    attributes &= ~FileAttributes.ReadOnly;
                    File.SetAttributes(filepath, attributes);
                }
            }

            var directoryInfo = new FileInfo(filepath).Directory;

            if (directoryInfo != null)
            {
                Directory.CreateDirectory(directoryInfo.FullName);
            }

            packagesFile.Save(filepath);

            NugetHelper.DisableWSAPExportSetting(filepath, packageExists);
        }
Esempio n. 4
0
        /// <summary>
        /// Builds a list of NugetPackages from the XML returned from the HTTP GET request issued at the given URL.
        /// Note that NuGet uses an Atom-feed (XML Syndicaton) superset called OData.
        /// See here http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
        /// </summary>
        /// <param name="url"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        private List <NugetPackage> GetPackagesFromUrl(string url, string password)
        {
            NugetHelper.LogVerbose("Getting packages from: {0}", url);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <NugetPackage> packages = new List <NugetPackage>();

            // Mono doesn't have a Certificate Authority, so we have to provide all validation manually.  Currently just accept anything.
            // See here: http://stackoverflow.com/questions/4926676/mono-webrequest-fails-with-https

            // remove all handlers
            ServicePointManager.ServerCertificateValidationCallback = null;

            // add anonymous handler
            ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, policyErrors) => true;

            Stream       responseStream = NugetHelper.RequestUrl(url, password, timeOut: 5000);
            StreamReader streamReader   = new StreamReader(responseStream);

            packages = NugetODataResponse.Parse(XDocument.Load(streamReader));

            foreach (var package in packages)
            {
                package.PackageSource = this;
            }

            stopwatch.Stop();
            NugetHelper.LogVerbose("Retreived {0} packages in {1} ms", packages.Count, stopwatch.ElapsedMilliseconds);

            return(packages);
        }
Esempio n. 5
0
        public void SetPreviewedPackage(NugetPackage package)
        {
            m_nugetPackage = package;

            var model = ScriptableObject.CreateInstance <PackageViewModel>();

            model.Package = package;

            SerializedObject serializedObject = new SerializedObject(model);

            LogPropertyPaths(serializedObject);
            this.Bind(serializedObject);

            this.Query <Label>("package-view--title").First().text            = package.Title;
            this.Query <Label>("package-view--author-text").First().text      = package.Authors;
            this.Query <Label>("package-view--description-text").First().text = package.Description;
            this.Query <Label>("package-view--license-text").First().text     = package.LicenseUrl;
            this.Query <VisualElement>("package-view--image").First().style.backgroundImage = package.Icon;

            bool isInstalled = NugetHelper.IsInstalled(package);

            this.Query <Button>("package-view--primary-action").First().text =
                isInstalled
                ? "Remove Package from Project"
                : "Add Package to Project";
        }
Esempio n. 6
0
    public void OnEnable()
    {
        var packages = NugetHelper.Search();

        foreach (var package in packages)
        {
            Debug.Log("Found Package: " + package.Title);
            m_currentlyBrowsing.Add(package);
        }

        // Each editor window contains a root VisualElement object
        VisualElement root = rootVisualElement;

        // A stylesheet can be added to a VisualElement.
        // The style will be applied to the VisualElement and all of its children.
        var styleSheet = AssetDatabase.LoadAssetAtPath <StyleSheet>("Assets/CPM/Scripts/Editor/ConvergePackageManager.uss");

        root.styleSheets.Add(styleSheet);

        BindToolbar();
        BindTwoPaneSplitView();
        BindBrowseList();
        BindPackageView();

        m_packageView = rootVisualElement.Query <PackageView>("package-view").First();
    }
Esempio n. 7
0
        /// <summary>
        /// Sets up viewmodels to be used in the individual mod loader pages.
        /// </summary>
        private static async Task SetupViewModelsAsync()
        {
            _ = Task.Run(BasicDllInjector.PreloadAddresses); // Fire and Forget
            var loaderConfig = LoaderConfigReader.ReadConfiguration();

            IoC.Kernel.Bind <LoaderConfig>().ToConstant(loaderConfig);
            IoC.GetConstant <MainPageViewModel>();
            IoC.GetConstant <AddAppViewModel>();       // Consumes MainPageViewModel, make sure it goes after it.
            IoC.GetConstant <ManageModsViewModel>();   // Consumes MainPageViewModel, LoaderConfig
            IoC.GetConstant <SettingsPageViewModel>(); // Consumes ManageModsViewModel, AddAppViewModel

            try
            {
                var helper = await NugetHelper.FromSourceUrlAsync(SharedConstants.NuGetApiEndpoint);

                IoC.Kernel.Rebind <NugetHelper>().ToConstant(helper);
                IoC.GetConstant <DownloadModsViewModel>(); // Consumes ManageModsViewModel, NugetHelper
            }
            catch (Exception)
            {
                // Probably no internet access.
            }


            /* Set loader DLL path. */
            SetLoaderPaths(loaderConfig, Path.GetDirectoryName(Environment.GetCommandLineArgs()[0]));
            LoaderConfigReader.WriteConfiguration(loaderConfig);
        }
Esempio n. 8
0
        /// <summary>
        /// Builds a list of NugetPackages from the XML returned from the HTTP GET request issued at the given URL.
        /// Note that NuGet uses an Atom-feed (XML Syndicaton) superset called OData.
        /// See here http://www.odata.org/documentation/odata-version-2-0/uri-conventions/
        /// </summary>
        /// <param name="url"></param>
        /// <returns></returns>
        private List <NugetPackage> GetPackagesFromUrl(string url)
        {
            NugetHelper.LogVerbose("Getting packages from: {0}", url);

            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            List <NugetPackage> packages = new List <NugetPackage>();

            try
            {
                HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(url);
                getRequest.Timeout          = 5000;
                getRequest.ReadWriteTimeout = 5000;
                Stream       responseStream = getRequest.GetResponse().GetResponseStream();
                StreamReader streamReader   = new StreamReader(responseStream);

                packages = NugetODataResponse.Parse(XDocument.Load(streamReader));

                foreach (var package in packages)
                {
                    package.PackageSource = this;
                }
            }
            catch (System.Exception e)
            {
                Debug.LogErrorFormat(e.ToString());
            }

            stopwatch.Stop();
            NugetHelper.LogVerbose("Retreived {0} packages in {1} ms", packages.Count, stopwatch.ElapsedMilliseconds);

            return(packages);
        }
        /// <summary>
        /// Some NuGet feeds such as Visual Studio Team Services do not implement the GetUpdates function.
        /// In that case this fallback function can be used to retrieve updates by using the FindPackagesById function.
        /// </summary>
        /// <param name="installedPackages">The list of currently installed packages.</param>
        /// <param name="includePrerelease">True to include prerelease packages (alpha, beta, etc).</param>
        /// <param name="includeAllVersions">True to include older versions that are not the latest version.</param>
        /// <param name="targetFrameworks">The specific frameworks to target?</param>
        /// <param name="versionContraints">The version constraints?</param>
        /// <returns>A list of all updates available.</returns>
        private List <NugetPackage> GetUpdatesFallback(IEnumerable <NugetPackage> installedPackages, bool includePrerelease = false, bool includeAllVersions = false, string targetFrameworks = "", string versionContraints = "")
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            Debug.Assert(string.IsNullOrEmpty(targetFrameworks) && string.IsNullOrEmpty(versionContraints)); // These features are not supported by this version of GetUpdates.

            List <NugetPackage> updates = new List <NugetPackage>();

            foreach (NugetPackage installedPackage in installedPackages)
            {
                string versionRange                   = string.Format("({0},)", installedPackage.Version); // Minimum of Current ID (exclusive) with no maximum (exclusive).
                NugetPackageIdentifier id             = new NugetPackageIdentifier(installedPackage.Id, versionRange);
                List <NugetPackage>    packageUpdates = FindPackagesById(id);

                if (!includePrerelease)
                {
                    packageUpdates.RemoveAll(p => p.IsPrerelease);
                }
                if (packageUpdates.Count == 0)
                {
                    continue;
                }

                int skip = includeAllVersions ? 0 : packageUpdates.Count - 1;
                updates.AddRange(packageUpdates.Skip(skip));
            }

            NugetHelper.LogVerbose("NugetPackageSource.GetUpdatesFallback took {0} ms", stopwatch.ElapsedMilliseconds);
            return(updates);
        }
Esempio n. 10
0
        /// <summary>
        /// Creates a new <see cref="NugetPackage"/> from the given <see cref="NuspecFile"/>.
        /// </summary>
        /// <param name="nuspec">The <see cref="NuspecFile"/> to use to create the <see cref="NugetPackage"/>.</param>
        /// <returns>The newly created <see cref="NugetPackage"/>.</returns>
        public static NugetPackage FromNuspec(NuspecFile nuspec)
        {
            NugetPackage package = new NugetPackage();

            package.Id           = nuspec.Id;
            package.Version      = nuspec.Version;
            package.Title        = nuspec.Title;
            package.Description  = nuspec.Description;
            package.ReleaseNotes = nuspec.ReleaseNotes;
            package.LicenseUrl   = nuspec.LicenseUrl;
            //package.DownloadUrl = not in a nuspec

            if (!string.IsNullOrEmpty(nuspec.IconUrl))
            {
                package.Icon = NugetHelper.DownloadImage(nuspec.IconUrl);
            }

            // if there is no title, just use the ID as the title
            if (string.IsNullOrEmpty(package.Title))
            {
                package.Title = package.Id;
            }

            package.Dependencies = nuspec.Dependencies;

            return(package);
        }
Esempio n. 11
0
        //集成测试[Fact]
        public void GetNewestVersion()
        {
            var npk = NugetHelper.GetLastestVersionPackage(Path.GetFullPath("../../pkgs"), "Package");

            npk.Version.ToString().Should().Be("3.0.0-pre");
            _testOutputHelper.WriteLine(npk.Version.ToString());
        }
Esempio n. 12
0
        private void Refresh(bool forceFullRefresh)
        {
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();

            try
            {
                if (forceFullRefresh)
                {
                    NugetHelper.ClearCachedCredentials();
                }

                // reload the NuGet.config file, in case it was changed after Unity opened, but before the manager window opened (now)
                NugetHelper.LoadNugetConfigFile();

                // if we are entering playmode, don't do anything
                if (EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    return;
                }

                NugetHelper.LogVerbose(hasRefreshed ? "NugetWindow reloading config" : "NugetWindow reloading config and updating packages");

                // set the window title
                titleContent = new GUIContent("NuGet");

                if (!hasRefreshed || forceFullRefresh)
                {
                    // reset the number to skip
                    numberToSkip = 0;

                    // TODO: Do we even need to load ALL of the data, or can we just get the Online tab packages?

                    EditorUtility.DisplayProgressBar("Opening NuGet", "Fetching packages from server...", 0.3f);
                    UpdateOnlinePackages();

                    EditorUtility.DisplayProgressBar("Opening NuGet", "Getting installed packages...", 0.6f);
                    NugetHelper.UpdateInstalledPackages();

                    EditorUtility.DisplayProgressBar("Opening NuGet", "Getting available updates...", 0.9f);
                    UpdateUpdatePackages();

                    // load the default icon from the Resources folder
                    defaultIcon = (Texture2D)Resources.Load("defaultIcon", typeof(Texture2D));
                }

                hasRefreshed = true;
            }
            catch (Exception e)
            {
                UnityEngine.Debug.LogErrorFormat("{0}", e.ToString());
            }
            finally
            {
                EditorUtility.ClearProgressBar();

                NugetHelper.LogVerbose("NugetWindow reloading took {0} ms", stopwatch.ElapsedMilliseconds);
            }
        }
Esempio n. 13
0
        /// <summary>
        /// Creates a NuGet.config file with the default settings at the given full filepath.
        /// </summary>
        /// <param name="filePath">The full filepath where to create the NuGet.config file.</param>
        /// <returns>The loaded <see cref="NugetConfigFile"/> loaded off of the newly created default file.</returns>
        public static NugetConfigFile CreateDefaultFile(string filePath)
        {
            const string contents =
                @"<?xml version=""1.0"" encoding=""utf-8""?>
<configuration>
    <packageSources>
       <clear/>
       <add key=""NuGet"" value=""http://www.nuget.org/api/v2/"" />
    </packageSources>
    <disabledPackageSources />
    <activePackageSource>
       <add key=""All"" value=""(Aggregate source)"" />
    </activePackageSource>
    <config>
       <add key=""repositoryPath"" value=""./Packages"" />
       <add key=""DefaultPushSource"" value=""http://www.nuget.org/api/v2/"" />
    </config>
</configuration>";

            File.WriteAllText(filePath, contents, new UTF8Encoding());

            AssetDatabase.Refresh();

            NugetHelper.DisableWSAPExportSetting(filePath, false);

            return(Load(filePath));
        }
Esempio n. 14
0
    public void InstallJsonTest()
    {
        NugetHelper.UninstallAll();

        var json608 = new NugetPackageIdentifier("Newtonsoft.Json", "6.0.8");

        Assert.IsTrue(NugetHelper.IsFullyUninstalled(json608), "The package is at least partially installed before we installed it: {0} {1}", json608.Id, json608.Version);

        var json701 = new NugetPackageIdentifier("Newtonsoft.Json", "7.0.1");

        Assert.IsTrue(NugetHelper.IsFullyUninstalled(json701), "The package is at least partially installed before we installed it: {0} {1}", json701.Id, json701.Version);

        // install a specific version
        NugetHelper.InstallIdentifier(json608);
        Assert.IsTrue(NugetHelper.IsInstalled(json608), "The package was NOT installed: {0} {1}", json608.Id, json608.Version);

        // install a newer version
        NugetHelper.InstallIdentifier(json701);
        Assert.IsTrue(NugetHelper.IsInstalled(json701), "The package was NOT installed: {0} {1}", json701.Id, json701.Version);

        // The previous version should have been removed.
        Assert.IsTrue(NugetHelper.IsFullyUninstalled(json608), "The package is STILL at least partially installed: {0} {1}", json608.Id, json608.Version);

        // try to install an old version while a newer is already installed
        NugetHelper.InstallIdentifier(json608);
        Assert.IsTrue(NugetHelper.IsInstalled(json701), "The package was NOT installed: {0} {1}", json701.Id, json701.Version);
        Assert.IsTrue(NugetHelper.IsFullyUninstalled(json608), "The package is installed and should not have been: {0} {1}", json608.Id, json608.Version);

        NugetHelper.UninstallAll();
        Assert.IsTrue(NugetHelper.IsFullyUninstalled(json701), "The package is STILL at least partially installed: {0} {1}", json701.Id, json701.Version);
    }
Esempio n. 15
0
        /// <summary>
        /// Loads a list of all currently installed packages by reading the packages.config file.
        /// </summary>
        /// <returns>A newly created <see cref="PackagesConfigFile"/>.</returns>
        public static PackagesConfigFile Load(string filepath)
        {
            PackagesConfigFile configFile = new PackagesConfigFile
            {
                Packages = new List <NugetPackageIdentifier>()
            };

            // Create a package.config file, if there isn't already one in the project
            if (!File.Exists(filepath))
            {
                Debug.LogFormat("No packages.config file found. Creating default at {0}", filepath);

                configFile.Save(filepath);

                AssetDatabase.Refresh();
            }

            XDocument packagesFile = XDocument.Load(filepath);

            // Force disable
            NugetHelper.DisableWSAPExportSetting(filepath, false);

            foreach (XElement packageElement in packagesFile.Root.Elements())
            {
                NugetPackage package = new NugetPackage
                {
                    Id      = packageElement.Attribute("id").Value,
                    Version = packageElement.Attribute("version").Value
                };
                configFile.Packages.Add(package);
            }

            return(configFile);
        }
Esempio n. 16
0
        private IEnumerable <PackageChange> DetermineChangedNugetPackages()
        {
            // Try to find a Directory.Packages.props file in the list of changed files
            var packagePropsPath = _changedFiles.Value
                                   .SingleOrDefault(f => f.EndsWith("Directory.Packages.props"));

            if (packagePropsPath is null)
            {
                return(Enumerable.Empty <PackageChange>());
            }

            // Get the contents of the file at from/to revisions
            var(fromFile, toFile) = _changesProvider.Value
                                    .GetTextFileContents(
                _executionData.RepositoryPath,
                packagePropsPath,
                _executionData.From,
                _executionData.To);

            // Parse props files into package and version dictionary
            var fromPackages = NugetHelper.ParseDirectoryPackageProps(fromFile);
            var toPackages   = NugetHelper.ParseDirectoryPackageProps(toFile);

            // Compare both dictionaries
            return(NugetHelper.DiffPackageDictionaries(fromPackages, toPackages));
        }
        private static NpkPath GetNpkPath(string packageDir, string pkgName)
        {
            var newbePk = NugetHelper.GetLastestVersionPackage(packageDir, pkgName);
            var npkPath = new NpkPath(Path.Combine(packageDir, $"{newbePk.Id}.{newbePk.Version.ToFullString()}"));

            return(npkPath);
        }
Esempio n. 18
0
        public void CheckPackageLibraryContent()
        {
            var p         = new NugetPackage("Unity", "4.0.1", "net45", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath());
            var installed = NugetHelper.InstallPackages(new[] { p }, false, null).First();

            Assert.AreEqual(6, installed.Libraries.Count());
        }
        private static List <string> GetBestStandaloneFrameworks()
        {
            int intDotNetVersion = (int)NugetHelper.DotNetVersion(BuildTargetGroup.Standalone); // c
            //bool using46 = DotNetVersion == ApiCompatibilityLevel.NET_4_6; // NET_4_6 option was added in Unity 5.6
            bool using46        = intDotNetVersion == 3;                                        // NET_4_6 = 3 in Unity 5.6 and Unity 2017.1 - use the hard-coded int value to ensure it works in earlier versions of Unity
            bool usingStandard2 = intDotNetVersion == 6;                                        // using .net standard 2.0

            var frameworkGroups = new List <string>(unityFrameworks);

            if (usingStandard2)
            {
                frameworkGroups.AddRange(netStandardFrameworks);
            }
            else if (using46)
            {
                if (NugetHelper.UnityVersion.Current.Major >= 2018)
                {
                    frameworkGroups.AddRange(net4Unity2018Frameworks);
                }

                if (NugetHelper.UnityVersion.Current.Major >= 2017)
                {
                    frameworkGroups.AddRange(net4Unity2017Frameworks);
                }

                frameworkGroups.AddRange(net3Frameworks);
                frameworkGroups.AddRange(netStandardFrameworks);
            }
            else
            {
                frameworkGroups.AddRange(net3Frameworks);
            }

            return(frameworkGroups);
        }
Esempio n. 20
0
        //集成测试[Fact]
        public void IntergationTest()
        {
            var npk = NugetHelper.GetLastestVersionPackage(@"D:\Codes\Repos\Newbe.Mahua.Framework\packages",
                                                           "Newbe.Mahua.CQP");

            npk.Version.ToFullString().Should().Be("1.0.1.2");
            _testOutputHelper.WriteLine(npk.Version.ToString());
        }
Esempio n. 21
0
        public async Task GetPackageVersions()
        {
            var packageName = "WeihanLi.Npoi";
            var versions    = (await NugetHelper.GetPackageVersions(packageName)).ToArray();

            Assert.NotEmpty(versions);
            Assert.Contains(versions, v => v.ToString().Equals("1.9.3"));
        }
Esempio n. 22
0
        public async Task GetPackages()
        {
            var prefix   = "WeihanLi";
            var packages = (await NugetHelper.GetPackages(prefix)).ToArray();

            Assert.NotEmpty(packages);
            Assert.Contains("WeihanLi.Common", packages);
        }
Esempio n. 23
0
        public void CompileTimeReferencesInstallOnDependency(string id, string version, string framework)
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage(id, version, framework, "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, true, null).ToList();
            NugetHelper.CheckPackagesConsistency(packages);
        }
Esempio n. 24
0
        public void TestNearestFrameworkAny(string version, string targetFramework)
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage("TestFrameworkAny", version, targetFramework, GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, true, null).ToList();
            NugetHelper.CheckPackagesConsistency(packages, true);
        }
Esempio n. 25
0
 static SystemProxy()
 {
     if (!IsPlayingOrWillChangePlaymode && !UnityEditorInternal.InternalEditorUtility.inBatchMode)
     {
         // restore packages - this will be called EVERY time the project is loaded or a code-file changes.
         NugetHelper.Restore();
     }
 }
Esempio n. 26
0
        public void ConsistencyCheck()
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage("Package A", "1.0.0", "net5", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("Package A", "2.0.0", "net5", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));

            Assert.Throws <Exceptions.MultiplePackagesFoundException>(() => NugetHelper.CheckPackagesConsistency(packages));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib1", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();
            //Should assert due to the missing dependency package
            Assert.Throws <Exceptions.DependencyNotFoundException>(() => NugetHelper.CheckPackagesConsistency(packages));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib1", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("CoreLib", "0.0.1", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("CoreLib", "0.0.2", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();
            //Should assert due to the different versions of the CoreLib checked as dependencies in the TestLib1 package
            Assert.Throws <Exceptions.MultipleDependenciesFoundException>(() => NugetHelper.CheckPackagesConsistency(packages));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib1", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, true, null).ToList();
            //Should assert due to the different versions of the CoreLib package
            Assert.Throws <Exceptions.MultipleDependenciesFoundException>(() => NugetHelper.CheckPackagesConsistency(packages));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("CoreLib", "0.0.1", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();
            //Should assert due to the unsupprted version of the CoreLib package
            Assert.Throws <Exceptions.InvalidDependencyFoundException>(() => NugetHelper.CheckPackagesConsistency(packages));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("CoreLib", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();
            //Although the Lib2 is build against the CoreLib;0.0.2 this test should pass.
            //This because Lib2 was built with version dependency CoreLib>=0.0.2
            NugetHelper.CheckPackagesConsistency(packages);

            //With the flag set to true, this thest should now fail, because the exact min version 0.0.2 is missing
            Assert.Throws <Exceptions.InvalidMinVersionDependencyFoundExceptio>(() => NugetHelper.CheckPackagesConsistency(packages, true));

            packages.Clear();
            packages.Add(new NugetPackage("TestLib2", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath(), false));
            packages.Add(new NugetPackage("CoreLib", "1.0.0", "netstandard2.0", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();
            //Although the Lib2 is build against the CoreLib;0.0.2 this test should pass.
            //This because hte packge TestLib2 is instantiated with the parameter dependencyForceMinVersion set to false.
            NugetHelper.CheckPackagesConsistency(packages, true);
        }
Esempio n. 27
0
        public void CompileTimeReferencesInstallOnPackage()
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage("Microsoft.CSharp", "4.0.1", "netstandard1.0", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetCompileTimeAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, true, null).ToList();
            NugetHelper.CheckPackagesConsistency(packages);
            packages.Clear();
        }
Esempio n. 28
0
 /* Construction - Deconstruction */
 public DownloadModsViewModel(NugetHelper nugetHelper)
 {
     _nugetHelper       = nugetHelper;
     DownloadModEntries = new ObservableCollection <DownloadModEntry>();
     PropertyChanged   += OnSearchQueryChanged;
     #pragma warning disable 4014
     GetSearchResults(); // Fire and forget.
     #pragma warning restore 4014
 }
Esempio n. 29
0
        public void VersionConsistencyCheckOnPackageOnDependency()
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage("TestVersionConflict", "1.0.0", "net45", GetLocalTestRepository(), null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages.Add(new NugetPackage("System.Management.Automation.dll", "10.0.10586.0", "net40", "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, true, null).ToList();
            NugetHelper.CheckPackagesConsistency(packages, true);
        }
Esempio n. 30
0
        public void EnsureImplementationAssembliesWhenAvailable(string id, string version, string framework)
        {
            var packages = new List <NugetPackage>();

            packages.Add(new NugetPackage(id, version, framework, "https://api.nuget.org/v3/index.json", null, NugetPackageType.DotNetImplementationAssembly, GetNugetCachePath()));
            packages = NugetHelper.InstallPackages(packages, false, null).ToList();

            Assert.IsTrue(packages.First().PackageType == NugetPackageType.DotNetImplementationAssembly);
        }