Skip to content

Commit

Permalink
Update template
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolayPianikov committed Jul 22, 2024
1 parent 1a00c7f commit 17ad49a
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 34 deletions.
31 changes: 22 additions & 9 deletions Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -184,7 +197,7 @@
{
output.Handled = true;
WriteLine(output.Line);
}).EnsureSuccess(r => default);
}).EnsureSuccess(_ => true);

new DotNetCustom("csi", "/?").WithShortName("Checking tool").Run().EnsureSuccess();

Expand All @@ -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");
Expand All @@ -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();
Expand Down
11 changes: 9 additions & 2 deletions CSharpInteractive.Templates/CSharpInteractive.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework/>
<TargetFrameworks>netstandard1.0</TargetFrameworks>
<TargetFramework>netstandard1.0</TargetFramework>
<IsPackable>true</IsPackable>
<IncludeBuildOutput>False</IncludeBuildOutput>
<IncludeSource>False</IncludeSource>
Expand All @@ -17,13 +17,20 @@
<PackageType>Template</PackageType>
<PackageReadmeFile>content/ConsoleApplication-CSharp/README.md</PackageReadmeFile>
<SuppressDependenciesWhenPacking>True</SuppressDependenciesWhenPacking>
<PackageIcon>_common\icon.png</PackageIcon>
</PropertyGroup>

<ItemGroup>
<PackageReference Remove="Microsoft.NETCore.App"/>
<Content Include="content\**">
<PackagePath>content</PackagePath>
</Content>
</ItemGroup>

<Content Include="$(MSBuildProjectDirectory)\..\icon.png">
<PackagePath>_common</PackagePath>
<Pack>true</Pack>
<Visible>false</Visible>
</Content>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="CSharpInteractive" Version="$(PackageVersion)"/>
<PackageReference Include="CSharpInteractive" Version="[$(CSharpInteractiveVersion), 1.2.0)"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -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
```

0 comments on commit 17ad49a

Please sign in to comment.