Save() public method

Saves a NuspecFile to the given filepath, automatically overwriting.
public Save ( string filePath ) : void
filePath string The full filepath to the .nuspec file to save.
return void
コード例 #1
0
ファイル: NuspecEditor.cs プロジェクト: tk-aria/NuGetForUnity
        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
        private static void CreateNuspecAndOpenEditor(string filepath)
        {
            if (!string.IsNullOrEmpty(Path.GetExtension(filepath)))
            {
                filepath = Path.GetDirectoryName(filepath);
            }

            if (filepath == null)
            {
                return;
            }

            var packageName = Path.GetFileName(filepath);

            filepath = Path.Combine(filepath, packageName + ".nuspec");

            var file = new NuspecFile
            {
                Id           = string.Format(DefaultFile.Id, packageName.ToLower()),
                Title        = packageName,
                Version      = DefaultFile.Version,
                Authors      = DefaultFile.Authors,
                Owners       = DefaultFile.Owners,
                LicenseUrl   = DefaultFile.LicenseUrl,
                ProjectUrl   = string.Format(DefaultFile.ProjectUrl, packageName),
                Description  = DefaultFile.Description,
                ReleaseNotes = DefaultFile.ReleaseNotes,
                Copyright    = DefaultFile.Copyright,
                IconUrl      = DefaultFile.IconUrl
            };

            file.Save(filepath);

            AssetDatabase.Refresh();

            // select the newly created .nuspec file
            var 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();
        }
コード例 #3
0
ファイル: NuspecEditor.cs プロジェクト: tk-aria/NuGetForUnity
        /// <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);
                }
            }
        }
コード例 #4
0
        /// <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);
                }
            }
        }
コード例 #5
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 packages is and does.";
            file.ReleaseNotes = "Notes for this specific release";
            file.Copyright = "Copyright 2016";
            file.IconUrl = "https://www.nuget.org/Content/Images/packageDefaultIcon-50x50.png";
            file.Save(filepath);

            AssetDatabase.Refresh();
        }
コード例 #6
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.");
                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);
            }
        }