示例#1
0
        protected static void CreateNuspecFile()
        {
            string filepath = Application.dataPath;

            if (Selection.activeObject != null && Selection.activeObject != Selection.activeGameObject)
            {
                string selectedFile = AssetDatabase.GetAssetPath(Selection.activeObject);
                filepath = selectedFile.Substring("Assets/".Length);
                filepath = Path.Combine(Application.dataPath, filepath);
            }

            if (!string.IsNullOrEmpty(Path.GetExtension(filepath)))
            {
                // if it was a file that was selected, replace the filename
                filepath  = filepath.Replace(Path.GetFileName(filepath), string.Empty);
                filepath += "MyPackage.nuspec";
            }
            else
            {
                // if it was a directory that was selected, simply add the filename
                filepath += "/MyPackage.nuspec";
            }

            Debug.LogFormat("Creating: {0}", filepath);

            NuspecFile file = new NuspecFile();

            file.Id           = "MyPackage";
            file.Version      = "0.0.1";
            file.Authors      = "Your Name";
            file.Owners       = "Your Name";
            file.LicenseUrl   = "http://your_license_url_here";
            file.ProjectUrl   = "http://your_project_url_here";
            file.Description  = "A description of what this package is and does.";
            file.Summary      = "A brief description of what this package is and does.";
            file.ReleaseNotes = "Notes for this specific release";
            file.Copyright    = "Copyright 2017";
            file.IconUrl      = "https://www.nuget.org/Content/Images/packageDefaultIcon-50x50.png";
            file.Save(filepath);

            AssetDatabase.Refresh();

            // select the newly created .nuspec file
            string dataPath = Application.dataPath.Substring(0, Application.dataPath.Length - "Assets".Length);

            Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(filepath.Replace(dataPath, string.Empty));

            // automatically display the editor with the newly created .nuspec file
            DisplayNuspecEditor();
        }
示例#2
0
        /// <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($"Save {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("Push to Server"))
                {
                    NugetHelper.Push(_nuspec, _filepath, _apiKey);
                }
            }
        }