Skip to content

Commit 17ad49a

Browse files
Update template
1 parent 1a00c7f commit 17ad49a

File tree

5 files changed

+41
-34
lines changed

5 files changed

+41
-34
lines changed

Build/Program.cs

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,25 @@
9191
.Build()
9292
.EnsureSuccess();
9393

94-
new DotNetPack()
95-
.WithProject(solutionFile)
96-
.WithConfiguration(configuration)
97-
.WithProps(buildProps)
98-
.Build()
99-
.EnsureSuccess();
94+
const string templateJson = "CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json";
95+
var content = File.ReadAllText(templateJson);
96+
var newContent = content.Replace("$(version)", packageVersion.ToString());
97+
File.WriteAllText(templateJson, newContent);
98+
IBuildResult result;
99+
try
100+
{
101+
result = new DotNetPack()
102+
.WithProject(solutionFile)
103+
.WithConfiguration(configuration)
104+
.WithProps(buildProps)
105+
.Build();
106+
}
107+
finally
108+
{
109+
File.WriteAllText(templateJson, content);
110+
}
111+
112+
result.EnsureSuccess();
100113

101114
foreach (var package in packages)
102115
{
@@ -184,7 +197,7 @@
184197
{
185198
output.Handled = true;
186199
WriteLine(output.Line);
187-
}).EnsureSuccess(r => default);
200+
}).EnsureSuccess(_ => true);
188201

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

@@ -195,7 +208,7 @@
195208
{
196209
output.Handled = true;
197210
WriteLine(output.Line);
198-
}).EnsureSuccess(r => default);;
211+
}).EnsureSuccess(_ => true);
199212

200213
var installTemplates = new DotNetCustom("new", "install", $"{templatesPackageId}::{packageVersion.ToString()}", "--nuget-source", templateOutputDir)
201214
.WithShortName("Installing template");
@@ -210,7 +223,7 @@
210223
try
211224
{
212225
var sampleProjectDir = Path.Combine("Samples", "MySampleLib", "MySampleLib.Tests");
213-
new DotNetNew("build", $"--package-version={packageVersion}", "-T", framework, "--no-restore")
226+
new DotNetNew("build", $"--version={packageVersion}", "-T", framework, "--no-restore")
214227
.WithWorkingDirectory(buildProjectDir)
215228
.WithShortName($"Creating a new {sampleProjectName}")
216229
.Run().EnsureSuccess();

CSharpInteractive.Templates/CSharpInteractive.Templates.csproj

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<TargetFramework/>
5-
<TargetFrameworks>netstandard1.0</TargetFrameworks>
5+
<TargetFramework>netstandard1.0</TargetFramework>
66
<IsPackable>true</IsPackable>
77
<IncludeBuildOutput>False</IncludeBuildOutput>
88
<IncludeSource>False</IncludeSource>
@@ -17,13 +17,20 @@
1717
<PackageType>Template</PackageType>
1818
<PackageReadmeFile>content/ConsoleApplication-CSharp/README.md</PackageReadmeFile>
1919
<SuppressDependenciesWhenPacking>True</SuppressDependenciesWhenPacking>
20+
<PackageIcon>_common\icon.png</PackageIcon>
2021
</PropertyGroup>
2122

2223
<ItemGroup>
2324
<PackageReference Remove="Microsoft.NETCore.App"/>
2425
<Content Include="content\**">
2526
<PackagePath>content</PackagePath>
2627
</Content>
27-
</ItemGroup>
2828

29+
<Content Include="$(MSBuildProjectDirectory)\..\icon.png">
30+
<PackagePath>_common</PackagePath>
31+
<Pack>true</Pack>
32+
<Visible>false</Visible>
33+
</Content>
34+
</ItemGroup>
35+
2936
</Project>

CSharpInteractive.Templates/content/ConsoleApplication-CSharp/.template.config/template.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
],
88
"name": "Build App",
99
"generatorVersions": "[1.0.0.0-*)",
10-
"description": "A build project for creating a command-line application to run TeamCity C# script on Windows, Linux, macOS and under TeamCity build server.",
10+
"description": "A build project for creating a command-line application to run C# script on Windows, Linux, macOS.",
1111
"groupIdentity": "Build.Projects",
1212
"precedence": "8000",
1313
"identity": "Build.Console",
@@ -31,13 +31,12 @@
3131
"type": "bind",
3232
"binding": "HostIdentifier"
3333
},
34-
"packageVersion": {
34+
"version": {
3535
"type": "parameter",
36-
"datatype": "text",
37-
"description": "Sets the referencing package version in the created project file.",
38-
"replaces": "$(PackageVersion)",
39-
"defaultValue": "1.1.*",
40-
"displayName": "Referencing package version"
36+
"datatype": "string",
37+
"description": "Version of CSharpInteractive that will be referenced.",
38+
"defaultValue": "$(version)",
39+
"replaces": "$(CSharpInteractiveVersion)"
4140
},
4241
"skipRestore": {
4342
"type": "parameter",

CSharpInteractive.Templates/content/ConsoleApplication-CSharp/Company.ConsoleApplication1.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="CSharpInteractive" Version="$(PackageVersion)"/>
11+
<PackageReference Include="CSharpInteractive" Version="[$(CSharpInteractiveVersion), 1.2.0)"/>
1212
</ItemGroup>
1313

1414
</Project>
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
1-
Install the C# script template [CSharpInteractive.Templates](https://www.nuget.org/packages/CSharpInteractive.Templates)
1+
This projects contains the script *__Program.csx__*. To run this script from the command line:
22

33
```shell
4-
dotnet new -i CSharpInteractive.Templates
5-
```
6-
7-
Create a console project "Build" containing a script from the template *__build__*
8-
9-
```shell
10-
dotnet new build -o ./Build
11-
```
12-
13-
This projects contains the script *__./Build/Program.csx__*. To run this script from the command line from the directory *__Build__*:
14-
15-
```shell
16-
dotnet csi Build
4+
dotnet csi Program.csx
175
```
186

197
To run as a .NET console application:
208

219
```shell
22-
dotnet run --project Build
10+
dotnet run
2311
```

0 commit comments

Comments
 (0)