From 17ad49ac6eb927e9b82e4a4df9b6fe77a10cc81c Mon Sep 17 00:00:00 2001 From: Nikolay Pianikov Date: Mon, 22 Jul 2024 12:12:37 +0300 Subject: [PATCH] Update template --- Build/Program.cs | 31 +++++++++++++------ .../CSharpInteractive.Templates.csproj | 11 +++++-- .../.template.config/template.json | 13 ++++---- .../Company.ConsoleApplication1.csproj | 2 +- .../ConsoleApplication-CSharp/README.md | 18 ++--------- 5 files changed, 41 insertions(+), 34 deletions(-) diff --git a/Build/Program.cs b/Build/Program.cs index fda9f5db..f4cf0cf7 100644 --- a/Build/Program.cs +++ b/Build/Program.cs @@ -91,12 +91,25 @@ .Build() .EnsureSuccess(); -new DotNetPack() - .WithProject(solutionFile) - .WithConfiguration(configuration) - .WithProps(buildProps) - .Build() - .EnsureSuccess(); +const string templateJson = "CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json"; +var content = File.ReadAllText(templateJson); +var newContent = content.Replace("$(version)", packageVersion.ToString()); +File.WriteAllText(templateJson, newContent); +IBuildResult result; +try +{ + result = new DotNetPack() + .WithProject(solutionFile) + .WithConfiguration(configuration) + .WithProps(buildProps) + .Build(); +} +finally +{ + File.WriteAllText(templateJson, content); +} + +result.EnsureSuccess(); foreach (var package in packages) { @@ -184,7 +197,7 @@ { output.Handled = true; WriteLine(output.Line); -}).EnsureSuccess(r => default); +}).EnsureSuccess(_ => true); new DotNetCustom("csi", "/?").WithShortName("Checking tool").Run().EnsureSuccess(); @@ -195,7 +208,7 @@ { output.Handled = true; WriteLine(output.Line); -}).EnsureSuccess(r => default);; +}).EnsureSuccess(_ => true); var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir) .WithShortName("Installing template"); @@ -210,7 +223,7 @@ try { var sampleProjectDir = Path.Combine("Samples", "MySampleLib", "MySampleLib.Tests"); - new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore") + new DotNetNew("build", $"--version={packageVersion}", "-T", framework, "--no-restore") .WithWorkingDirectory(buildProjectDir) .WithShortName($"Creating a new {sampleProjectName}") .Run().EnsureSuccess(); diff --git a/CSharpInteractive.Templates/CSharpInteractive.Templates.csproj b/CSharpInteractive.Templates/CSharpInteractive.Templates.csproj index 94644789..3c96a3f8 100644 --- a/CSharpInteractive.Templates/CSharpInteractive.Templates.csproj +++ b/CSharpInteractive.Templates/CSharpInteractive.Templates.csproj @@ -2,7 +2,7 @@ - netstandard1.0 + netstandard1.0 true False False @@ -17,6 +17,7 @@ Template content/ConsoleApplication-CSharp/README.md True + _common\icon.png @@ -24,6 +25,12 @@ content - + + _common + true + false + + + diff --git a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json index 6a092649..3c888138 100644 --- a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json +++ b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json @@ -7,7 +7,7 @@ ], "name": "Build App", "generatorVersions": "[1.0.0.0-*)", - "description": "A build project for creating a command-line application to run TeamCity C# script on Windows, Linux, macOS and under TeamCity build server.", + "description": "A build project for creating a command-line application to run C# script on Windows, Linux, macOS.", "groupIdentity": "Build.Projects", "precedence": "8000", "identity": "Build.Console", @@ -31,13 +31,12 @@ "type": "bind", "binding": "HostIdentifier" }, - "packageVersion": { + "version": { "type": "parameter", - "datatype": "text", - "description": "Sets the referencing package version in the created project file.", - "replaces": "$(PackageVersion)", - "defaultValue": "1.1.*", - "displayName": "Referencing package version" + "datatype": "string", + "description": "Version of CSharpInteractive that will be referenced.", + "defaultValue": "$(version)", + "replaces": "$(CSharpInteractiveVersion)" }, "skipRestore": { "type": "parameter", diff --git a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Company.ConsoleApplication1.csproj b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Company.ConsoleApplication1.csproj index afd52ddb..83ba5425 100644 --- a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Company.ConsoleApplication1.csproj +++ b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Company.ConsoleApplication1.csproj @@ -8,7 +8,7 @@ - + diff --git a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/README.md b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/README.md index 0ebd6b73..b3130bdd 100644 --- a/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/README.md +++ b/CSharpInteractive.Templates/content/ConsoleApplication-CSharp/README.md @@ -1,23 +1,11 @@ -Install the C# script template [CSharpInteractive.Templates](https://www.nuget.org/packages/CSharpInteractive.Templates) +This projects contains the script *__Program.csx__*. To run this script from the command line: ```shell -dotnet new -i CSharpInteractive.Templates -``` - -Create a console project "Build" containing a script from the template *__build__* - -```shell -dotnet new build -o ./Build -``` - -This projects contains the script *__./Build/Program.csx__*. To run this script from the command line from the directory *__Build__*: - -```shell -dotnet csi Build +dotnet csi Program.csx ``` To run as a .NET console application: ```shell -dotnet run --project Build +dotnet run ```