コード例 #1
0
        private static void ProcessBuildRelatedFile(Project project, ConfigureView view, string packageFolder, string sourceFileName, string targetFileName)
        {
            var targetPath = Path.Combine(packageFolder, targetFileName);

            if (File.Exists(targetPath))
            {
                return;
            }

            File.Copy(Path.Combine(_extensionPath, ".package", sourceFileName), targetPath);

            var packageName = project.Name;

            var contents = File.ReadAllText(targetPath)
                           .Replace("#{PackageName}#", packageName)
                           .Replace("#{Owners}#", string.IsNullOrWhiteSpace(view.Owners.Text) ? view.Authors.Text : view.Owners.Text);

            File.WriteAllText(targetPath, contents);
        }
コード例 #2
0
        private void ConfigureBuildFolder(Project project)
        {
            var projectFolder = Path.GetDirectoryName(project.Properties.Item("FullPath").Value.ToString());

            if (string.IsNullOrEmpty(projectFolder))
            {
                throw new ApplicationException("Could not determine project path.");
            }

            var packageFolderProjectItem = FindFolder(project, ".package");
            var packageFolder            = Path.Combine(projectFolder, ".package");

            if (Directory.Exists(packageFolder))
            {
                VsShellUtilities.ShowMessageBox(
                    ServiceProvider,
                    $"Package folder '{packageFolder}' already exists.",
                    Title,
                    OLEMSGICON.OLEMSGICON_INFO,
                    OLEMSGBUTTON.OLEMSGBUTTON_OK,
                    OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST);

                return;
            }

            var view = new ConfigureView();

            try
            {
                if (view.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                if (packageFolderProjectItem == null)
                {
                    packageFolderProjectItem = project.ProjectItems.AddFromDirectory(Path.Combine(projectFolder, ".package"));
                }

                CopyBuildRelatedFile(packageFolder, "Shuttle.NuGetPackager.MSBuild.dll");
                CopyBuildRelatedFile(packageFolder, "Shuttle.NuGetPackager.targets");
                ProcessBuildRelatedFile(project, view, packageFolder, "package.msbuild.template", "package.msbuild");
                ProcessBuildRelatedFile(project, view, packageFolder, "AssemblyInfo.cs.template", "AssemblyInfo.cs.template");

                File.WriteAllText(Path.Combine(packageFolder, "package.nuspec.template"), GetNuspecTemplate(view, project));

                packageFolderProjectItem.ProjectItems.AddFromFile(Path.Combine(packageFolder, "Shuttle.NuGetPackager.MSBuild.dll"));
                packageFolderProjectItem.ProjectItems.AddFromFile(Path.Combine(packageFolder, "Shuttle.NuGetPackager.targets"));
                packageFolderProjectItem.ProjectItems.AddFromFile(Path.Combine(packageFolder, "package.msbuild"));
                packageFolderProjectItem.ProjectItems.AddFromFile(Path.Combine(packageFolder, "package.nuspec.template"));
                packageFolderProjectItem.ProjectItems.AddFromFile(Path.Combine(packageFolder, "AssemblyInfo.cs.template"));

                project.Save();

                ConfigureProjectFile(project, projectFolder);
            }
            finally
            {
                view.Dispose();
            }
        }
コード例 #3
0
        private string GetNuspecTemplate(ConfigureView view, Project project)
        {
            var result = new StringBuilder();

            result.AppendLine("<?xml version=\"1.0\"?>");
            result.AppendLine();
            result.AppendLine("<package>");
            result.AppendLine("\t<metadata>");
            result.AppendLine($"\t\t<id>{(view.ExplicitPackageName.Checked ? view.PackageName.Text : project.Name)}</id>");
            result.AppendLine("\t\t<version>#{SemanticVersion}#</version>");
            result.AppendLine($"\t\t<authors>{view.Authors.Text}</authors>");
            result.AppendLine($"\t\t<owners>{view.Owners.Text}</owners>");

            switch ((string)view.LicenseType.SelectedItem ?? string.Empty)
            {
            case "Expression":
            {
                result.AppendLine($"\t\t<license type=\"expression\">{view.License.Text}</license>");
                break;
            }

            case "File":
            {
                result.AppendLine($"\t\t<license type=\"file\">{Path.GetFileName(view.License.Text)}</license>");
                break;
            }
            }

            if (view.LicenseType.SelectedIndex > 0)
            {
                result.AppendLine($"\t\t<requireLicenseAcceptance>{view.RequireLicenseAcceptance.Checked.ToString().ToLower()}</requireLicenseAcceptance>");
            }

            if (view.HasIcon.Checked)
            {
                result.AppendLine($"\t\t<icon>images\\{Path.GetFileName(view.IconPath.Text)}</icon>");
            }

            if (!string.IsNullOrWhiteSpace(view.RepositoryUrl.Text))
            {
                result.AppendLine($"\t\t<repository type=\"git\" url=\"{view.RepositoryUrl.Text}\" />");
            }

            if (!string.IsNullOrWhiteSpace(view.ProjectUrl.Text))
            {
                result.AppendLine($"\t\t<projectUrl>{view.ProjectUrl.Text}</projectUrl>");
            }

            result.AppendLine($"\t\t<description>{view.Description.Text}</description>");
            result.AppendLine($"\t\t<copyright>Copyright (c) #{{Year}}#, {(string.IsNullOrWhiteSpace(view.Owners.Text) ? view.Authors.Text : view.Owners.Text)}</copyright>");
            result.AppendLine($"\t\t<tags>{view.Tags.Text}</tags>");

            result.AppendLine("\t\t<dependencies>");
            result.AppendLine("#{Dependencies}#");
            result.AppendLine("\t\t</dependencies>");
            result.AppendLine("\t</metadata>");
            result.AppendLine("\t<files>");

            if (view.HasIcon.Checked)
            {
                result.AppendLine($"\t\t<file src=\"{view.IconPath.Text}\" target=\"images\" />");
            }

            if (((string)view.LicenseType.SelectedItem ?? string.Empty).Equals("File", StringComparison.InvariantCultureIgnoreCase))
            {
                result.AppendLine($"\t\t<file src=\"{view.License.Text}\" target=\"\" />");
            }

            result.AppendLine("\t\t<file src=\"lib\\**\\*.*\" target=\"lib\" />");
            result.AppendLine("\t</files>");
            result.AppendLine("</package>");

            return(result.ToString());
        }