/// <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); }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public NugetPackage GetSpecificPackage(NugetPackageIdentifier package) { if (package.HasVersionRange) { return(FindPackagesById(package).FirstOrDefault()); } if (IsLocalPath) { string localPackagePath = Path.Combine(ExpandedPath, string.Format("./{0}.{1}.nupkg", package.Id, package.Version)); if (File.Exists(localPackagePath)) { NugetPackage localPackage = NugetPackage.FromNupkgFile(localPackagePath); return(localPackage); } else { return(null); } } else { string url = string.Format("{0}Packages(Id='{1}',Version='{2}')", ExpandedPath, package.Id, package.Version); try { return(GetPackagesFromUrl(url, UserName, ExpandedPassword).First()); } catch (Exception e) { Debug.LogErrorFormat("Unable to retrieve package from {0}\n{1}", url, e.ToString()); return(null); } } }
/// <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 = "") { 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) { List <NugetPackage> packageUpdates = new List <NugetPackage>(); string versionRange = string.Format("({0},)", installedPackage.Version); // Minimum of Current ID (exclusive) with no maximum (exclusive). NugetPackageIdentifier id = new NugetPackageIdentifier(installedPackage.Id, versionRange); packageUpdates = FindPackagesById(id); NugetPackage mostRecentPrerelease = includePrerelease ? packageUpdates.FindLast(p => p.IsPrerelease) : default(NugetPackage); packageUpdates.RemoveAll(p => p.IsPrerelease && p != mostRecentPrerelease); if (!includeAllVersions && packageUpdates.Count > 0) { packageUpdates.RemoveRange(0, packageUpdates.Count - 1); } updates.AddRange(packageUpdates); } return(updates); }
/// <summary> /// Add a "dependancy" node; /// </summary> private void addDependancy(XElement dependencyElement) { NugetPackageIdentifier dependency = new NugetPackageIdentifier(); dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty; dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty; Dependencies.Add(dependency); }
/// <summary> /// Loads a .nuspec file inside the given <see cref="XDocument"/>. /// </summary> /// <param name="nuspecDocument">The .nuspec file as an <see cref="XDocument"/>.</param> /// <returns>The newly loaded <see cref="NuspecFile"/>.</returns> public static NuspecFile Load(XDocument nuspecDocument) { NuspecFile nuspec = new NuspecFile(); string nuspecNamespace = nuspecDocument.Root.GetDefaultNamespace().ToString(); XElement package = nuspecDocument.Element(XName.Get("package", nuspecNamespace)); XElement metadata = package.Element(XName.Get("metadata", nuspecNamespace)); nuspec.Id = (string)metadata.Element(XName.Get("id", nuspecNamespace)) ?? string.Empty; nuspec.Version = (string)metadata.Element(XName.Get("version", nuspecNamespace)) ?? string.Empty; nuspec.Title = (string)metadata.Element(XName.Get("title", nuspecNamespace)) ?? string.Empty; nuspec.Authors = (string)metadata.Element(XName.Get("authors", nuspecNamespace)) ?? string.Empty; nuspec.Owners = (string)metadata.Element(XName.Get("owners", nuspecNamespace)) ?? string.Empty; nuspec.LicenseUrl = (string)metadata.Element(XName.Get("licenseUrl", nuspecNamespace)) ?? string.Empty; nuspec.ProjectUrl = (string)metadata.Element(XName.Get("projectUrl", nuspecNamespace)) ?? string.Empty; nuspec.IconUrl = (string)metadata.Element(XName.Get("iconUrl", nuspecNamespace)) ?? string.Empty; nuspec.RequireLicenseAcceptance = bool.Parse((string)metadata.Element(XName.Get("requireLicenseAcceptance", nuspecNamespace)) ?? "False"); nuspec.Description = (string)metadata.Element(XName.Get("description", nuspecNamespace)) ?? string.Empty; nuspec.ReleaseNotes = (string)metadata.Element(XName.Get("releaseNotes", nuspecNamespace)) ?? string.Empty; nuspec.Copyright = (string)metadata.Element(XName.Get("copyright", nuspecNamespace)); nuspec.Tags = (string)metadata.Element(XName.Get("tags", nuspecNamespace)) ?? string.Empty; nuspec.Dependencies = new List <NugetPackageIdentifier>(); var dependenciesElement = metadata.Element(XName.Get("dependencies", nuspecNamespace)); if (dependenciesElement != null) { foreach (var dependencyElement in dependenciesElement.Elements(XName.Get("dependency", nuspecNamespace))) { NugetPackageIdentifier dependency = new NugetPackageIdentifier(); dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty; dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty; nuspec.Dependencies.Add(dependency); } } nuspec.Files = new List <NuspecContentFile>(); var filesElement = package.Element(XName.Get("files", nuspecNamespace)); if (filesElement != null) { //UnityEngine.Debug.Log("Loading files!"); foreach (var fileElement in filesElement.Elements(XName.Get("file", nuspecNamespace))) { NuspecContentFile file = new NuspecContentFile(); file.Source = (string)fileElement.Attribute("src") ?? string.Empty; file.Target = (string)fileElement.Attribute("target") ?? string.Empty; nuspec.Files.Add(file); } } return(nuspec); }
private void DrawDepencency(NugetPackageIdentifier dependency) { NugetPackage fullDependency = installedPackages.Find(p => p.Id == dependency.Id); if (fullDependency != null) { DrawPackage(fullDependency); } else { Debug.LogErrorFormat("{0} {1} is not installed!", dependency.Id, dependency.Version); } }
/// <summary> /// Adds a package to the packages.config file. /// </summary> /// <param name="package">The NugetPackage to add to the packages.config file.</param> public void AddPackage(NugetPackageIdentifier package) { var existingPackage = Packages.Find(p => p.Id.ToLower() == package.Id.ToLower()); if (existingPackage != null) { if (existingPackage < package) { SystemProxy.LogWarning($"{existingPackage.Id} {existingPackage.Version} is already listed in the packages.config file. Updating to {package.Version}"); Packages.Remove(existingPackage); Packages.Add(package); } else if (existingPackage > package) { SystemProxy.LogWarning($"Trying to add {package.Id} {package.Version} to the packages.config file. {existingPackage.Version} is already listed, so using that."); } } else { Packages.Add(package); } }
/// <summary> /// Adds a package to the packages.config file. /// </summary> /// <param name="package">The NugetPackage to add to the packages.config file.</param> public void AddPackage(NugetPackageIdentifier package) { NugetPackageIdentifier existingPackage = Packages.Find(p => p.Id.ToLower() == package.Id.ToLower()); if (existingPackage != null) { if (existingPackage < package) { Debug.LogWarningFormat("{0} {1} is already listed in the packages.config file. Updating to {2}", existingPackage.Id, existingPackage.Version, package.Version); Packages.Remove(existingPackage); Packages.Add(package); } else if (existingPackage > package) { Debug.LogWarningFormat("Trying to add {0} {1} to the packages.config file. {2} is already listed, so using that.", package.Id, package.Version, existingPackage.Version); } } else { Packages.Add(package); } }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public List <NugetPackage> FindPackagesById(NugetPackageIdentifier package) { List <NugetPackage> foundPackages = null; if (IsLocalPath) { // determine local path string localPackagePath; if (IsLocalPathAndVersion33) { localPackagePath = NugetPackage.PathLocal33Get(ExpandedPath, package.Id, package.Version); } else { localPackagePath = NugetPackage.PathLocalGet(ExpandedPath, package.Id, package.Version); } if (File.Exists(localPackagePath)) { string localPackagePath = Path.Combine(ExpandedPath, string.Format("./{0}.{1}.nupkg", package.Id, package.Version)); if (File.Exists(localPackagePath)) { NugetPackage localPackage = NugetPackage.FromNupkgFile(localPackagePath); foundPackages = new List <NugetPackage> { localPackage }; } else { foundPackages = new List <NugetPackage>(); } } else { // Try to find later versions of the same package var packages = GetLocalPackages(package.Id, true, true); foundPackages = new List <NugetPackage>(packages.SkipWhile(x => !package.InRange(x))); } } else { // See here: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ // Note: without $orderby=Version, the Version filter below will not work string url = string.Format("{0}FindPackagesById()?id='{1}'&$orderby=Version asc", ExpandedPath, package.Id); // Are we looking for a specific package? if (!package.HasVersionRange) { url = string.Format("{0}&$filter=Version eq '{1}'", url, package.Version); } try { foundPackages = GetPackagesFromUrl(url, UserName, ExpandedPassword); } catch (Exception e) { foundPackages = new List <NugetPackage>(); Debug.LogErrorFormat("Unable to retrieve package list from {0}\n{1}", url, e.ToString()); } } if (foundPackages != null) { // Return all the packages in the range of versions specified by 'package'. foundPackages.RemoveAll(p => !package.InRange(p)); foundPackages.Sort(); foreach (NugetPackage foundPackage in foundPackages) { foundPackage.PackageSource = this; } } return(foundPackages); }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// If an exact match isn't found, it selects the next closest version available. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public NugetPackage GetSpecificPackage(NugetPackageIdentifier package) { return(FindPackagesById(package).FirstOrDefault()); }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// If an exact match isn't found, it selects the next closest version available. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public List <NugetPackage> FindPackagesById(NugetPackageIdentifier package) { List <NugetPackage> foundPackages = null; if (IsLocalPath) { // determine local path string localPackagePath; if (IsLocalPathAndVersion33) { localPackagePath = NugetPackage.PathLocal33Get(ExpandedPath, package.Id, package.Version); } else { localPackagePath = NugetPackage.PathLocalGet(ExpandedPath, package.Id, package.Version); } if (File.Exists(localPackagePath)) { NugetPackage localPackage = NugetPackage.FromNupkgFile(localPackagePath); foundPackages = new List <NugetPackage> { localPackage }; } else { // TODO: Sort the local packages? Currently assuming they are in alphabetical order due to the filesystem. // TODO: Optimize to no longer use GetLocalPackages, since that loads the .nupkg itself // Try to find later versions of the same package var packages = GetLocalPackages(package.Id, true, true); foundPackages = new List <NugetPackage>(packages.SkipWhile(x => !package.InRange(x))); } } else { // See here: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ string url = string.Empty; // We used to rely on expressions such as &$filter=Version ge '9.0.1' to find versions in a range, but the results were sorted alphabetically. This // caused version 10.0.0 to be less than version 9.0.0. In order to work around this issue, we'll request all versions and perform filtering ourselves. url = string.Format("{0}FindPackagesById()?$orderby=Version asc&id='{1}'", ExpandedPath, package.Id); try { foundPackages = GetPackagesFromUrl(url, ExpandedPassword); } catch (System.Exception e) { foundPackages = new List <NugetPackage>(); Debug.LogErrorFormat("Unable to retrieve package list from {0}\n{1}", url, e.ToString()); } foundPackages.Sort(); if (foundPackages.Exists(p => package.InRange(p))) { // Return all the packages in the range of versions specified by 'package'. foundPackages.RemoveAll(p => !package.InRange(p)); } else { // There are no packages in the range of versions specified by 'package'. // Return the most recent version after the version specified by 'package'. foundPackages.RemoveAll(p => package.CompareVersion(p.Version) < 0); if (foundPackages.Count > 0) { foundPackages.RemoveRange(1, foundPackages.Count - 1); } } } if (foundPackages != null) { foreach (NugetPackage foundPackage in foundPackages) { foundPackage.PackageSource = this; } } return(foundPackages); }
protected static void CheckForUpdates() { const string url = "https://github.com/GlitchEnzo/NuGetForUnity/releases"; #if UNITY_2017_1_OR_NEWER // UnityWebRequest is not available in Unity 5.2, which is the currently the earliest version supported by NuGetForUnity. using (UnityWebRequest request = UnityWebRequest.Get(url)) { request.Send(); #else using (WWW request = new WWW(url)) { #endif NugetHelper.LogVerbose("HTTP GET {0}", url); while (!request.isDone) { EditorUtility.DisplayProgressBar("Checking updates", null, 0.0f); } EditorUtility.ClearProgressBar(); string latestVersion = null; string latestVersionDownloadUrl = null; string response = null; #if UNITY_2017_1_OR_NEWER if (!request.isNetworkError && !request.isHttpError) { response = request.downloadHandler.text; } #else if (request.error == null) { response = request.text; } #endif if (response != null) { latestVersion = GetLatestVersonFromReleasesHtml(response, out latestVersionDownloadUrl); } if (latestVersion == null) { EditorUtility.DisplayDialog( "Unable to Determine Updates", string.Format("Couldn't find release information at {0}.", url), "OK"); return; } NugetPackageIdentifier current = new NugetPackageIdentifier("NuGetForUnity", NugetPreferences.VERSION); NugetPackageIdentifier latest = new NugetPackageIdentifier("NuGetForUnity", latestVersion); if (current >= latest) { EditorUtility.DisplayDialog( "No Updates Available", string.Format("Your version of NuGetForUnity is up to date.\nVersion {0}.", NugetPreferences.VERSION), "OK"); return; } // New version is available. Give user options for installing it. switch (EditorUtility.DisplayDialogComplex( "Update Available", string.Format("Current Version: {0}\nLatest Version: {1}", NugetPreferences.VERSION, latestVersion), "Install Latest", "Open Releases Page", "Cancel")) { case 0: Application.OpenURL(latestVersionDownloadUrl); break; case 1: Application.OpenURL(url); break; case 2: break; } } }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// If an exact match isn't found, it selects the next closest version available. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public NugetPackage GetSpecificPackage(NugetPackageIdentifier package) { NugetPackage foundPackage = null; if (IsLocalPath) { string localPackagePath = System.IO.Path.Combine(Path, string.Format("./{0}.{1}.nupkg", package.Id, package.Version)); if (File.Exists(localPackagePath)) { foundPackage = NugetPackage.FromNupkgFile(localPackagePath); } else { // TODO: Sort the local packages? Currently assuming they are in alphabetical order due to the filesystem. // TODO: Optimize to no longer use GetLocalPackages, since that loads the .nupkg itself // Try to find later versions of the same package var packages = GetLocalPackages(package.Id, true, true); foundPackage = packages.SkipWhile(x => !package.InRange(x)).FirstOrDefault(); } } else { // See here: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ string url = string.Empty; if (!package.HasVersionRange) { url = string.Format("{0}FindPackagesById()?$orderby=Version asc&id='{1}'&$filter=Version ge '{2}'", Path, package.Id, package.Version); } else { url = string.Format("{0}FindPackagesById()?$orderby=Version asc&id='{1}'&$filter=", Path, package.Id); bool hasMin = false; if (!string.IsNullOrEmpty(package.MinimumVersion)) { // Some packages append extraneous ".0"s to the end of the version number for dependencies // For example, the actual package version is "1.0", but the dependency is listed as "1.0.0" // In these cases the NuGet server fails to return the "1.0" version when that version string is queried // While this seems to be a flaw in the NuGet server, we shall fix it here by removing the last .0, if there is one // Note that it only removes the last one and not all, this can be made to loop if additional problems are found in other packages var minVersion = package.MinimumVersion.EndsWith(".0") ? package.MinimumVersion.Remove(package.MinimumVersion.LastIndexOf(".0", StringComparison.Ordinal)) : package.MinimumVersion; hasMin = true; if (package.IsMinInclusive) { url += string.Format("Version ge '{0}'", minVersion); } else { url += string.Format("Version gt '{0}'", minVersion); } } if (!string.IsNullOrEmpty(package.MaximumVersion)) { if (hasMin) { url += " and "; } if (package.IsMaxInclusive) { url += string.Format("Version le '{0}'", package.MaximumVersion); } else { url += string.Format("Version lt '{0}'", package.MaximumVersion); } } else { if (package.IsMaxInclusive) { // if there is no MaxVersion specified, but the Max is Inclusive, then it is an EXACT version match with the stored MINIMUM url += string.Format(" and Version le '{0}'", package.MinimumVersion); } } } foundPackage = GetPackagesFromUrl(url).FirstOrDefault(); } if (foundPackage != null) { foundPackage.PackageSource = this; } return(foundPackage); }
/// <summary> /// Use the Unity GUI to draw the controls. /// </summary> protected void OnGUI() { if (nuspec == null) { Reload(); } if (nuspec == null) { titleContent = new GUIContent("[NO NUSPEC]"); EditorGUILayout.LabelField("There is no .nuspec file selected."); } else { EditorGUIUtility.labelWidth = 100; nuspec.Id = EditorGUILayout.TextField(new GUIContent("ID", "The name of the package."), nuspec.Id); nuspec.Version = EditorGUILayout.TextField(new GUIContent("Version", "The semantic version of the package."), nuspec.Version); nuspec.Authors = EditorGUILayout.TextField(new GUIContent("Authors", "The authors of the package."), nuspec.Authors); nuspec.Owners = EditorGUILayout.TextField(new GUIContent("Owners", "The owners of the package."), nuspec.Owners); nuspec.LicenseUrl = EditorGUILayout.TextField(new GUIContent("License URL", "The URL for the license of the package."), nuspec.LicenseUrl); nuspec.ProjectUrl = EditorGUILayout.TextField(new GUIContent("Project URL", "The URL of the package project."), nuspec.ProjectUrl); nuspec.IconUrl = EditorGUILayout.TextField(new GUIContent("Icon URL", "The URL for the icon of the package."), nuspec.IconUrl); nuspec.RequireLicenseAcceptance = EditorGUILayout.Toggle(new GUIContent("Require License Acceptance", "Does the package license need to be accepted before use?"), nuspec.RequireLicenseAcceptance); nuspec.Description = EditorGUILayout.TextField(new GUIContent("Description", "The description of the package."), nuspec.Description); nuspec.Summary = EditorGUILayout.TextField(new GUIContent("Summary", "The brief description of the package."), nuspec.Summary); nuspec.ReleaseNotes = EditorGUILayout.TextField(new GUIContent("Release Notes", "The release notes for this specific version of the package."), nuspec.ReleaseNotes); nuspec.Copyright = EditorGUILayout.TextField(new GUIContent("Copyright", "The copyright details for the package."), nuspec.Copyright); nuspec.Tags = EditorGUILayout.TextField(new GUIContent("Tags", "The space-delimited list of tags and keywords that describe the package and aid discoverability of packages through search and filtering."), nuspec.Tags); dependenciesExpanded = EditorGUILayout.Foldout(dependenciesExpanded, new GUIContent("Dependencies", "The list of NuGet packages that this packages depends on.")); if (dependenciesExpanded) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(50); // automatically fill in the dependencies based upon the "root" packages currently installed in the project if (GUILayout.Button(new GUIContent("Automatically Fill Dependencies", "Populates the list of dependencies with the \"root\" NuGet packages currently installed in the project."))) { NugetHelper.UpdateInstalledPackages(); List <NugetPackage> installedPackages = NugetHelper.InstalledPackages.ToList(); // default all packages to being roots List <NugetPackage> roots = new List <NugetPackage>(installedPackages); // remove a package as a root if another package is dependent on it foreach (NugetPackage package in installedPackages) { NugetFrameworkGroup packageFrameworkGroup = NugetHelper.GetBestDependencyFrameworkGroupForCurrentSettings(package); foreach (NugetPackageIdentifier dependency in packageFrameworkGroup.Dependencies) { roots.RemoveAll(p => p.Id == dependency.Id); } } // remove all existing dependencies from the .nuspec nuspec.Dependencies.Clear(); nuspec.Dependencies.Add(new NugetFrameworkGroup()); nuspec.Dependencies[0].Dependencies = roots.Cast <NugetPackageIdentifier>().ToList(); } } EditorGUILayout.EndHorizontal(); // display the dependencies NugetPackageIdentifier toDelete = null; NugetFrameworkGroup nuspecFrameworkGroup = NugetHelper.GetBestDependencyFrameworkGroupForCurrentSettings(nuspec); foreach (var dependency in nuspecFrameworkGroup.Dependencies) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(75); float prevLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 50; dependency.Id = EditorGUILayout.TextField(new GUIContent("ID", "The ID of the dependency package."), dependency.Id); EditorGUILayout.EndHorizontal(); //int oldSeletedIndex = IndexOf(ref existingComponents, dependency.Id); //int newSelectIndex = EditorGUILayout.Popup("Name", oldSeletedIndex, existingComponents); //if (oldSeletedIndex != newSelectIndex) //{ // dependency.Name = existingComponents[newSelectIndex]; //} EditorGUILayout.BeginHorizontal(); GUILayout.Space(75); dependency.Version = EditorGUILayout.TextField(new GUIContent("Version", "The version number of the dependency package. (specify ranges with =><)"), dependency.Version); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(75); if (GUILayout.Button("Remove " + dependency.Id)) { toDelete = dependency; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUIUtility.labelWidth = prevLabelWidth; } if (toDelete != null) { nuspecFrameworkGroup.Dependencies.Remove(toDelete); } EditorGUILayout.BeginHorizontal(); { GUILayout.Space(50); if (GUILayout.Button("Add Dependency")) { nuspecFrameworkGroup.Dependencies.Add(new NugetPackageIdentifier()); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); if (GUILayout.Button(string.Format("Save {0}", Path.GetFileName(filepath)))) { nuspec.Save(filepath); } EditorGUILayout.Separator(); if (GUILayout.Button(string.Format("Pack {0}.nupkg", Path.GetFileNameWithoutExtension(filepath)))) { NugetHelper.Pack(filepath); } EditorGUILayout.Separator(); apiKey = EditorGUILayout.TextField(new GUIContent("API Key", "The API key to use when pushing the package to the server"), apiKey); if (GUILayout.Button(string.Format("Push to Server"))) { NugetHelper.Push(nuspec, filepath, apiKey); } } }
/// <summary> /// Removes a package from the packages.config file. /// </summary> /// <param name="package">The NugetPackage to remove from the packages.config file.</param> public void RemovePackage(NugetPackageIdentifier package) { Packages.Remove(package); }
/// <summary> /// Loads a .nuspec file inside the given <see cref="XDocument"/>. /// </summary> /// <param name="nuspecDocument">The .nuspec file as an <see cref="XDocument"/>.</param> /// <returns>The newly loaded <see cref="NuspecFile"/>.</returns> public static NuspecFile Load(XDocument nuspecDocument) { NuspecFile nuspec = new NuspecFile(); string nuspecNamespace = nuspecDocument.Root.GetDefaultNamespace().ToString(); XElement package = nuspecDocument.Element(XName.Get("package", nuspecNamespace)); XElement metadata = package.Element(XName.Get("metadata", nuspecNamespace)); nuspec.Id = (string)metadata.Element(XName.Get("id", nuspecNamespace)) ?? string.Empty; nuspec.Version = (string)metadata.Element(XName.Get("version", nuspecNamespace)) ?? string.Empty; nuspec.Title = (string)metadata.Element(XName.Get("title", nuspecNamespace)) ?? string.Empty; nuspec.Authors = (string)metadata.Element(XName.Get("authors", nuspecNamespace)) ?? string.Empty; nuspec.Owners = (string)metadata.Element(XName.Get("owners", nuspecNamespace)) ?? string.Empty; nuspec.LicenseUrl = (string)metadata.Element(XName.Get("licenseUrl", nuspecNamespace)) ?? string.Empty; nuspec.ProjectUrl = (string)metadata.Element(XName.Get("projectUrl", nuspecNamespace)) ?? string.Empty; nuspec.IconUrl = (string)metadata.Element(XName.Get("iconUrl", nuspecNamespace)) ?? string.Empty; nuspec.RequireLicenseAcceptance = bool.Parse((string)metadata.Element(XName.Get("requireLicenseAcceptance", nuspecNamespace)) ?? "False"); nuspec.Description = (string)metadata.Element(XName.Get("description", nuspecNamespace)) ?? string.Empty; nuspec.Summary = (string)metadata.Element(XName.Get("summary", nuspecNamespace)) ?? string.Empty; nuspec.ReleaseNotes = (string)metadata.Element(XName.Get("releaseNotes", nuspecNamespace)) ?? string.Empty; nuspec.Copyright = (string)metadata.Element(XName.Get("copyright", nuspecNamespace)); nuspec.Tags = (string)metadata.Element(XName.Get("tags", nuspecNamespace)) ?? string.Empty; var repositoryElement = metadata.Element(XName.Get("repository", nuspecNamespace)); if (repositoryElement != null) { nuspec.RepositoryType = (string)repositoryElement.Attribute(XName.Get("type")) ?? string.Empty; nuspec.RepositoryUrl = (string)repositoryElement.Attribute(XName.Get("url")) ?? string.Empty; nuspec.RepositoryBranch = (string)repositoryElement.Attribute(XName.Get("branch")) ?? string.Empty; nuspec.RepositoryCommit = (string)repositoryElement.Attribute(XName.Get("commit")) ?? string.Empty; } var dependenciesElement = metadata.Element(XName.Get("dependencies", nuspecNamespace)); if (dependenciesElement != null) { // Dependencies specified for specific target frameworks foreach (var frameworkGroup in dependenciesElement.Elements(XName.Get("group", nuspecNamespace))) { NugetFrameworkGroup group = new NugetFrameworkGroup(); group.TargetFramework = ConvertFromNupkgTargetFrameworkName((string)frameworkGroup.Attribute("targetFramework") ?? string.Empty); foreach (var dependencyElement in frameworkGroup.Elements(XName.Get("dependency", nuspecNamespace))) { NugetPackageIdentifier dependency = new NugetPackageIdentifier(); dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty; dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty; group.Dependencies.Add(dependency); } nuspec.Dependencies.Add(group); } // Flat dependency list if (nuspec.Dependencies.Count == 0) { NugetFrameworkGroup group = new NugetFrameworkGroup(); foreach (var dependencyElement in dependenciesElement.Elements(XName.Get("dependency", nuspecNamespace))) { NugetPackageIdentifier dependency = new NugetPackageIdentifier(); dependency.Id = (string)dependencyElement.Attribute("id") ?? string.Empty; dependency.Version = (string)dependencyElement.Attribute("version") ?? string.Empty; group.Dependencies.Add(dependency); } nuspec.Dependencies.Add(group); } } var filesElement = package.Element(XName.Get("files", nuspecNamespace)); if (filesElement != null) { //UnityEngine.Debug.Log("Loading files!"); foreach (var fileElement in filesElement.Elements(XName.Get("file", nuspecNamespace))) { NuspecContentFile file = new NuspecContentFile(); file.Source = (string)fileElement.Attribute("src") ?? string.Empty; file.Target = (string)fileElement.Attribute("target") ?? string.Empty; nuspec.Files.Add(file); } } return(nuspec); }
/// <summary> /// Use the Header GUI to draw the controls since the Inspector GUI method call is disabled by Unity. /// </summary> protected override void OnHeaderGUI() { // draw the normal header base.OnHeaderGUI(); if (isNuspec) { EditorGUIUtility.labelWidth = 100; nuspec.Id = EditorGUILayout.TextField(new GUIContent("ID", "The name of the package."), nuspec.Id); nuspec.Version = EditorGUILayout.TextField(new GUIContent("Version", "The semantic version of the package."), nuspec.Version); nuspec.Authors = EditorGUILayout.TextField(new GUIContent("Authors", "The authors of the package."), nuspec.Authors); nuspec.Owners = EditorGUILayout.TextField(new GUIContent("Owners", "The owners of the package."), nuspec.Owners); nuspec.LicenseUrl = EditorGUILayout.TextField(new GUIContent("License URL", "The URL for the license of the package."), nuspec.LicenseUrl); nuspec.ProjectUrl = EditorGUILayout.TextField(new GUIContent("Project URL", "The URL of the package project."), nuspec.ProjectUrl); nuspec.IconUrl = EditorGUILayout.TextField(new GUIContent("Icon URL", "The URL for the icon of the package."), nuspec.IconUrl); nuspec.RequireLicenseAcceptance = EditorGUILayout.Toggle(new GUIContent("Require License Acceptance", "Does the package license need to be accepted before use?"), nuspec.RequireLicenseAcceptance); nuspec.Description = EditorGUILayout.TextField(new GUIContent("Description", "The description of the package."), nuspec.Description); nuspec.ReleaseNotes = EditorGUILayout.TextField(new GUIContent("Release Notes", "The release notes for this specific version of the package."), nuspec.ReleaseNotes); nuspec.Copyright = EditorGUILayout.TextField(new GUIContent("Copyright", "The copyright of the package."), nuspec.Copyright); nuspec.Tags = EditorGUILayout.TextField(new GUIContent("Tags", "The tags of the package."), nuspec.Tags); dependenciesExpanded = EditorGUILayout.Foldout(dependenciesExpanded, "Dependencies"); if (dependenciesExpanded) { EditorGUILayout.BeginHorizontal(); { GUILayout.Space(50); // automatically fill in the dependencies based upon the "root" packages currently installed in the project if (GUILayout.Button("Automatically Fill Dependencies")) { List <NugetPackage> installedPackages = NugetHelper.GetInstalledPackages().Values.ToList(); // default all packages to being roots List <NugetPackage> roots = new List <NugetPackage>(installedPackages); // remove a package as a root if another package is dependent on it foreach (NugetPackage package in installedPackages) { foreach (NugetPackageIdentifier dependency in package.Dependencies) { roots.RemoveAll(p => p.Id == dependency.Id); } } // remove all existing dependencies from the .nuspec nuspec.Dependencies.Clear(); nuspec.Dependencies = roots.Cast <NugetPackageIdentifier>().ToList(); } } EditorGUILayout.EndHorizontal(); // display the dependencies NugetPackageIdentifier toDelete = null; foreach (var dependency in nuspec.Dependencies) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(75); float prevLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 50; dependency.Id = EditorGUILayout.TextField(new GUIContent("ID", "The ID of the dependency package."), dependency.Id); EditorGUILayout.EndHorizontal(); //int oldSeletedIndex = IndexOf(ref existingComponents, dependency.Id); //int newSelectIndex = EditorGUILayout.Popup("Name", oldSeletedIndex, existingComponents); //if (oldSeletedIndex != newSelectIndex) //{ // dependency.Name = existingComponents[newSelectIndex]; //} EditorGUILayout.BeginHorizontal(); GUILayout.Space(75); dependency.Version = EditorGUILayout.TextField(new GUIContent("Version", "The version number of the dependency package. (specify ranges with =><)"), dependency.Version); EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { GUILayout.Space(75); if (GUILayout.Button("Remove " + dependency.Id)) { toDelete = dependency; } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUIUtility.labelWidth = prevLabelWidth; } if (toDelete != null) { nuspec.Dependencies.Remove(toDelete); } EditorGUILayout.BeginHorizontal(); { GUILayout.Space(50); if (GUILayout.Button("Add Dependency")) { nuspec.Dependencies.Add(new NugetPackageIdentifier()); } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.Separator(); if (GUILayout.Button(string.Format("Save {0}", Path.GetFileName(filepath)))) { nuspec.Save(filepath); } EditorGUILayout.Separator(); if (GUILayout.Button(string.Format("Pack {0}.nupkg", Path.GetFileNameWithoutExtension(filepath)))) { NugetHelper.Pack(filepath); } EditorGUILayout.Separator(); apiKey = EditorGUILayout.TextField(new GUIContent("API Key", "The API key to use when pushing the package to the server"), apiKey); if (GUILayout.Button(string.Format("Push to Server"))) { NugetHelper.Push(nuspec, filepath, apiKey); } } }
/// <summary> /// Gets a NugetPackage from the NuGet server that matches (or is in range of) the <see cref="NugetPackageIdentifier"/> given. /// </summary> /// <param name="package">The <see cref="NugetPackageIdentifier"/> containing the ID and Version of the package to get.</param> /// <returns>The retrieved package, if there is one. Null if no matching package was found.</returns> public List <NugetPackage> FindPackagesById(NugetPackageIdentifier package) { List <NugetPackage> foundPackages = null; if (IsLocalPath) { if (!package.HasVersionRange) { string localPackagePath = Path.Combine(ExpandedPath, string.Format("./{0}.{1}.nupkg", package.Id, package.Version)); if (File.Exists(localPackagePath)) { NugetPackage localPackage = NugetPackage.FromNupkgFile(localPackagePath); foundPackages = new List <NugetPackage> { localPackage }; } else { foundPackages = new List <NugetPackage>(); } } else { // TODO: Optimize to no longer use GetLocalPackages, since that loads the .nupkg itself foundPackages = GetLocalPackages(package.Id, true, true); } } else { // See here: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ string url = string.Format("{0}FindPackagesById()?id='{1}'", ExpandedPath, package.Id); // Are we looking for a specific package? if (!package.HasVersionRange) { url = string.Format("{0}&$filter=Version eq '{1}'", url, package.Version); } try { foundPackages = GetPackagesFromUrl(url, UserName, ExpandedPassword); } catch (Exception e) { foundPackages = new List <NugetPackage>(); Debug.LogErrorFormat("Unable to retrieve package list from {0}\n{1}", url, e.ToString()); } } if (foundPackages != null) { // Return all the packages in the range of versions specified by 'package'. foundPackages.RemoveAll(p => !package.InRange(p)); foundPackages.Sort(); foreach (NugetPackage foundPackage in foundPackages) { foundPackage.PackageSource = this; } } return(foundPackages); }
/// <summary> /// Parses the given <see cref="XDocument"/> and returns the list of <see cref="NugetPackage"/>s contained within. /// </summary> /// <param name="document">The <see cref="XDocument"/> that is the OData XML response from the NuGet server.</param> /// <returns>The list of <see cref="NugetPackage"/>s read from the given XML.</returns> public static List <NugetPackage> Parse(XDocument document) { List <NugetPackage> packages = new List <NugetPackage>(); var packageEntries = document.Root.Elements(XName.Get("entry", AtomNamespace)); foreach (var entry in packageEntries) { NugetPackage package = new NugetPackage(); package.Id = entry.GetAtomElement("title").Value; package.DownloadUrl = entry.GetAtomElement("content").Attribute("src").Value; var entryProperties = entry.Element(XName.Get("properties", MetaDataNamespace)); package.Title = entryProperties.GetProperty("Title"); package.Version = entryProperties.GetProperty("Version"); package.Description = entryProperties.GetProperty("Description"); package.Summary = entryProperties.GetProperty("Summary"); package.ReleaseNotes = entryProperties.GetProperty("ReleaseNotes"); package.LicenseUrl = entryProperties.GetProperty("LicenseUrl"); package.ProjectUrl = entryProperties.GetProperty("ProjectUrl"); package.Authors = entryProperties.GetProperty("Authors"); package.DownloadCount = int.Parse(entryProperties.GetProperty("DownloadCount")); string iconUrl = entryProperties.GetProperty("IconUrl"); if (!string.IsNullOrEmpty(iconUrl)) { package.Icon = NugetHelper.DownloadImage(iconUrl); } // if there is no title, just use the ID as the title if (string.IsNullOrEmpty(package.Title)) { package.Title = package.Id; } // Get dependencies string rawDependencies = entryProperties.GetProperty("Dependencies"); if (!string.IsNullOrEmpty(rawDependencies)) { var dependencyGroups = new Dictionary <string, NugetFrameworkGroup>(); string[] dependencies = rawDependencies.Split('|'); foreach (var dependencyString in dependencies) { string[] details = dependencyString.Split(':'); string framework = string.Empty; if (details.Length > 2) { framework = details[2]; } NugetFrameworkGroup group; if (!dependencyGroups.TryGetValue(framework, out group)) { group = new NugetFrameworkGroup(); group.TargetFramework = framework; dependencyGroups.Add(framework, group); } var dependency = new NugetPackageIdentifier(details[0], details[1]); // some packages (ex: FSharp.Data - 2.1.0) have inproper "semi-empty" dependencies such as: // "Zlib.Portable:1.10.0:portable-net40+sl50+wp80+win80|::net40" // so we need to only add valid dependencies and skip invalid ones if (!string.IsNullOrEmpty(dependency.Id) && !string.IsNullOrEmpty(dependency.Version)) { group.Dependencies.Add(dependency); } } foreach (var group in dependencyGroups.Values) { package.Dependencies.Add(group); } } packages.Add(package); } return(packages); }
/// <summary> /// Removes a package from the packages.config file. /// </summary> /// <param name="package">The NugetPackage to remove from the packages.config file.</param> public void RemovePackage(NugetPackageIdentifier package) { Packages.RemoveAll(p => p.CompareTo(package) == 0); }
/// <summary> /// Parses the given <see cref="XDocument"/> and returns the list of <see cref="NugetPackage"/>s contained within. /// </summary> /// <param name="document">The <see cref="XDocument"/> that is the OData XML response from the NuGet server.</param> /// <returns>The list of <see cref="NugetPackage"/>s read from the given XML.</returns> public static List <NugetPackage> Parse(XDocument document) { List <NugetPackage> packages = new List <NugetPackage>(); var packageEntries = document.Root.Elements(XName.Get("entry", AtomNamespace)); foreach (var entry in packageEntries) { NugetPackage package = new NugetPackage(); package.Id = entry.GetAtomElement("title").Value; package.DownloadUrl = entry.GetAtomElement("content").Attribute("src").Value; var entryProperties = entry.Element(XName.Get("properties", MetaDataNamespace)); package.Title = entryProperties.GetProperty("Title"); package.Version = entryProperties.GetProperty("Version"); package.Description = entryProperties.GetProperty("Description"); package.ReleaseNotes = entryProperties.GetProperty("ReleaseNotes"); package.LicenseUrl = entryProperties.GetProperty("LicenseUrl"); package.ProjectUrl = entryProperties.GetProperty("ProjectUrl"); string iconUrl = entryProperties.GetProperty("IconUrl"); if (!string.IsNullOrEmpty(iconUrl)) { NugetImageLoader.TryDownloadImage(iconUrl, tex => { package.Icon = tex; }); } // if there is no title, just use the ID as the title if (string.IsNullOrEmpty(package.Title)) { package.Title = package.Id; } // Get dependencies package.Dependencies = new List <NugetPackageIdentifier>(); string rawDependencies = entryProperties.GetProperty("Dependencies"); if (!string.IsNullOrEmpty(rawDependencies)) { var dependencyGroups = new Dictionary <string, NugetFrameworkGroup>(); string[] dependencies = rawDependencies.Split('|'); foreach (var dependencyString in dependencies) { string[] details = dependencyString.Split(':'); var dependency = new NugetPackageIdentifier(details[0], details[1]); // some packages (ex: FSharp.Data - 2.1.0) have inproper "semi-empty" dependencies such as: // "Zlib.Portable:1.10.0:portable-net40+sl50+wp80+win80|::net40" // so we need to only add valid dependencies and skip invalid ones if (string.IsNullOrEmpty(dependency.Id) && string.IsNullOrEmpty(dependency.Version)) { continue; } string framework = string.Empty; if (details.Length > 2) { framework = details[2]; } NugetFrameworkGroup group; if (dependencyGroups.TryGetValue(framework, out group)) { group.Dependencies.Add(dependency); } else { group = new NugetFrameworkGroup(); group.Dependencies = new List <NugetPackageIdentifier>(); group.Dependencies.Add(dependency); dependencyGroups.Add(framework, group); } } // find the correct group for this project int intDotNetVersion = (int)NugetHelper.DotNetVersion; //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 NugetFrameworkGroup selectedGroup = null; foreach (var kvPair in dependencyGroups.OrderByDescending(x => x.Key)) { string framework = kvPair.Key; NugetFrameworkGroup group = kvPair.Value; // Select the highest .NET library available that is supported // See here: https://docs.nuget.org/ndocs/schema/target-frameworks if (using46 && framework == "net462") { selectedGroup = group; break; } else if (using46 && framework == "net461") { selectedGroup = group; break; } else if (using46 && framework == "net46") { selectedGroup = group; break; } else if (using46 && framework == "net452") { selectedGroup = group; break; } else if (using46 && framework == "net451") { selectedGroup = group; break; } else if (using46 && framework == "net45") { selectedGroup = group; break; } else if (using46 && framework == "net403") { selectedGroup = group; break; } else if (using46 && (framework == "net40" || framework == "net4")) { selectedGroup = group; break; } else if (framework == "net35") { selectedGroup = group; break; } else if (framework == "net20") { selectedGroup = group; break; } else if (framework == "net11") { selectedGroup = group; break; } else if (framework == string.Empty) { selectedGroup = group; break; } } if (selectedGroup != null) { package.Dependencies = selectedGroup.Dependencies; } } packages.Add(package); } return(packages); }
/// <summary> /// Use the Unity GUI to draw the controls. /// </summary> protected void OnGUI() { if (nuspec == null) { Reload(); } if (nuspec == null) { titleContent = new GUIContent("[NO NUSPEC]"); EditorGUILayout.LabelField("There is no .nuspec file selected."); return; } { EditorGUIUtility.labelWidth = 100; nuspec.Id = EditorGUILayout.TextField(new GUIContent("ID", "The id of the package."), nuspec.Id); nuspec.Title = EditorGUILayout.TextField(new GUIContent("Title", "The name of the package."), nuspec.Title); nuspec.Version = EditorGUILayout.TextField(new GUIContent("Version", "The semantic version of the package."), nuspec.Version); nuspec.Authors = EditorGUILayout.TextField(new GUIContent("Authors", "The authors of the package."), nuspec.Authors); nuspec.Owners = EditorGUILayout.TextField(new GUIContent("Owners", "The owners of the package."), nuspec.Owners); nuspec.LicenseUrl = EditorGUILayout.TextField(new GUIContent("License URL", "The URL for the license of the package."), nuspec.LicenseUrl); nuspec.ProjectUrl = EditorGUILayout.TextField(new GUIContent("Project URL", "The URL of the package project."), nuspec.ProjectUrl); nuspec.IconUrl = EditorGUILayout.TextField(new GUIContent("Icon URL", "The URL for the icon of the package."), nuspec.IconUrl); nuspec.RequireLicenseAcceptance = EditorGUILayout.Toggle(new GUIContent("Require License Acceptance", "Does the package license need to be accepted before use?"), nuspec.RequireLicenseAcceptance); nuspec.Description = EditorGUILayout.TextField(new GUIContent("Description", "The description of the package."), nuspec.Description); nuspec.ReleaseNotes = EditorGUILayout.TextField(new GUIContent("Release Notes", "The release notes for this specific version of the package."), nuspec.ReleaseNotes); nuspec.Copyright = EditorGUILayout.TextField(new GUIContent("Copyright", "The copyright details for the package."), nuspec.Copyright); nuspec.Tags = EditorGUILayout.TextField(new GUIContent("Tags", "The space-delimited list of tags and keywords that describe the package and aid discoverability of packages through search and filtering."), nuspec.Tags); using (new EditorGUILayout.HorizontalScope()) { dependenciesExpanded = EditorGUILayout.Foldout(dependenciesExpanded, new GUIContent("Dependencies", "The list of NuGet packages that this packages depends on.")); if (dependenciesExpanded) { GUILayout.FlexibleSpace(); // automatically fill in the dependencies based upon packages currently installed in the project if (GUILayout.Button(new GUIContent("Automatically Fill Dependencies", "Populates the list of dependencies with all NuGet packages currently installed in the project."))) { NugetHelper.UpdateInstalledPackages(); var installedPackages = NugetHelper.InstalledPackages.ToList(); // exclude yourself from the list installedPackages.RemoveAll(p => p.Id == nuspec.Id); // remove all existing dependencies from the .nuspec nuspec.Dependencies.Clear(); nuspec.Dependencies.Add(new NugetFrameworkGroup()); nuspec.Dependencies[0].Dependencies = installedPackages.Cast <NugetPackageIdentifier>().ToList(); } } } if (dependenciesExpanded) { EditorGUILayout.Space(); // display the dependencies NugetPackageIdentifier toDelete = null; var nuspecFrameworkGroup = NugetHelper.GetBestDependencyFrameworkGroupForCurrentSettings(nuspec); foreach (var dependency in nuspecFrameworkGroup.Dependencies) { EditorGUILayout.BeginHorizontal(); GUILayout.Space(25); GUILayout.Label("ID", GUILayout.Width(25), GUILayout.Height(20)); dependency.Id = GUILayout.TextField(dependency.Id, GUILayout.Height(20)); GUILayout.Label("Version ", GUILayout.Width(50), GUILayout.Height(20)); dependency.Version = GUILayout.TextField(dependency.Version, GUILayout.Width(150), GUILayout.Height(20)); GUILayout.Space(5); if (GUILayout.Button("X", GUILayout.Width(20))) { toDelete = dependency; } EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); } if (toDelete != null) { nuspecFrameworkGroup.Dependencies.Remove(toDelete); } EditorGUILayout.BeginHorizontal(); { GUILayout.Space(25); if (GUILayout.Button("Add Dependency")) { nuspecFrameworkGroup.Dependencies.Add(new NugetPackageIdentifier()); } } EditorGUILayout.EndHorizontal(); } GUILayout.Space(10); packingExpanded = EditorGUILayout.Foldout(packingExpanded, new GUIContent("Pack and Push to Server")); if (packingExpanded) { if (GUILayout.Button($"Pack {Path.GetFileNameWithoutExtension(filepath)}.nupkg")) { NugetHelper.Pack(filepath); } EditorGUILayout.Separator(); apiKey = EditorGUILayout.TextField(new GUIContent("API Key", "The API key to use when pushing the package to the server"), apiKey); if (GUILayout.Button("Push to Server")) { NugetHelper.Push(nuspec, filepath, apiKey); } } GUILayout.FlexibleSpace(); using (new EditorGUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); var style = new GUIStyle(GUI.skin.button) { normal = { textColor = Color.green } }; if (GUILayout.Button($"Save {Path.GetFileName(filepath)}", style, GUILayout.Width(400), GUILayout.Height(50))) { nuspec.Save(filepath); } GUILayout.FlexibleSpace(); } GUILayout.Space(20); } }