Skip to content

Commit ccefb5f

Browse files
Improvements for DotNet Tool, Dxm & NuGet templates (#14)
* Added editorconfig to solution templates (DotNet Tool, Dxm & NuGet). Updated Skyline.DataMiner.CICD.FileSystem NuGet references to the latest version. Updated DotNet tool templates to use .NET 8 (.NET 6 is almost deprecated) * Added most common code as well to save time. serilog, and fixed an async return issue. * Return Task<int> * fixes * Fix indentation and convert some files to spaces to match with the new editorconfig files * Adding gitignore file --------- Co-authored-by: Jan Staelens <jan.staelens@skyline.be>
1 parent 6759c2d commit ccefb5f

File tree

19 files changed

+374
-253
lines changed

19 files changed

+374
-253
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
**/bin/*
2+
**/obj/*

working/templatepack.csproj

+15-24
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
<Authors>SkylineCommunications</Authors>
99
<Description>This package contains DataMiner dotnet templates for use in Visual Studio and the dotnet CLI to be used by Skyline employees.</Description>
1010
<PackageTags>dotnet-new;templates;DataMiner</PackageTags>
11-
<PackageLicenseFile>LICENSE</PackageLicenseFile>
12-
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
13-
<PackageIcon>Icon.png</PackageIcon>
14-
<PackageReadmeFile>README.md</PackageReadmeFile>
15-
11+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
12+
<PackageRequireLicenseAcceptance>False</PackageRequireLicenseAcceptance>
13+
<PackageIcon>Icon.png</PackageIcon>
14+
<PackageReadmeFile>README.md</PackageReadmeFile>
15+
1616
<TargetFramework>netstandard2.0</TargetFramework>
1717
<IncludeContentInPack>true</IncludeContentInPack>
1818
<IncludeBuildOutput>false</IncludeBuildOutput>
@@ -21,24 +21,15 @@
2121
<NoDefaultExcludes>true</NoDefaultExcludes>
2222
</PropertyGroup>
2323

24-
<ItemGroup>
25-
<None Include="..\nuget\Icon.png">
26-
<Pack>True</Pack>
27-
<PackagePath>\</PackagePath>
28-
</None>
29-
<None Include="..\LICENSE">
30-
<Pack>True</Pack>
31-
<PackagePath>\</PackagePath>
32-
</None>
33-
<None Include="..\README.md">
34-
<Pack>True</Pack>
35-
<PackagePath>\</PackagePath>
36-
</None>
37-
</ItemGroup>
38-
39-
<ItemGroup>
40-
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
41-
<Compile Remove="**\*" />
42-
</ItemGroup>
24+
<ItemGroup>
25+
<None Include="..\nuget\Icon.png" Pack="true" PackagePath="" />
26+
<None Include="..\LICENSE" Pack="true" PackagePath="" />
27+
<None Include="..\README.md" Pack="true" PackagePath="" />
28+
</ItemGroup>
29+
30+
<ItemGroup>
31+
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**" />
32+
<Compile Remove="**\*" />
33+
</ItemGroup>
4334

4435
</Project>
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<PackAsTool>true</PackAsTool>
6-
<ToolCommandName>$ToolCommandName$</ToolCommandName>
7-
<ImplicitUsings>disable</ImplicitUsings>
8-
<Nullable>disable</Nullable>
9-
<AssemblyName>$PackageId$</AssemblyName>
10-
<RootNamespace>$PackageId$</RootNamespace>
11-
<PackageVersion>1.0.1</PackageVersion>
12-
<Version>1.0.1</Version>
13-
<PackageTags>Skyline;DataMiner</PackageTags>
14-
<PackageProjectUrl>https://skyline.be</PackageProjectUrl>
15-
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
17-
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
18-
<PackageIcon>Icon.png</PackageIcon>
19-
<GenerateDocumentationFile>True</GenerateDocumentationFile>
20-
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
21-
<Authors>SkylineCommunications</Authors>
22-
<Company>Skyline Communications</Company>
23-
<Description>$PackageDescription$</Description>
24-
<RepositoryType Condition="$(hasGitRepoUrl)">git</RepositoryType>
25-
<RepositoryUrl Condition="$(hasGitRepoUrl)">$GitRepoUrl$</RepositoryUrl>
26-
</PropertyGroup>
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<PackAsTool>true</PackAsTool>
6+
<ToolCommandName>$ToolCommandName$</ToolCommandName>
7+
<ImplicitUsings>disable</ImplicitUsings>
8+
<Nullable>disable</Nullable>
9+
<AssemblyName>$PackageId$</AssemblyName>
10+
<RootNamespace>$PackageId$</RootNamespace>
11+
<PackageVersion>1.0.1</PackageVersion>
12+
<Version>1.0.1</Version>
13+
<PackageTags>Skyline;DataMiner</PackageTags>
14+
<PackageProjectUrl>https://skyline.be</PackageProjectUrl>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
17+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
18+
<PackageIcon>Icon.png</PackageIcon>
19+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
20+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
21+
<Authors>SkylineCommunications</Authors>
22+
<Company>Skyline Communications</Company>
23+
<Description>$PackageDescription$</Description>
24+
<RepositoryType Condition="$(hasGitRepoUrl)">git</RepositoryType>
25+
<RepositoryUrl Condition="$(hasGitRepoUrl)">$GitRepoUrl$</RepositoryUrl>
26+
</PropertyGroup>
2727

28-
<ItemGroup>
29-
<None Include="README.md" Pack="true" PackagePath="" />
30-
<None Include="LICENSE.txt" Pack="true" PackagePath="" />
31-
<None Include="nuget\Icon.png" Pack="true" PackagePath="" />
32-
</ItemGroup>
33-
<ItemGroup>
34-
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.3" />
35-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
36-
</ItemGroup>
28+
<ItemGroup>
29+
<None Include="README.md" Pack="true" PackagePath="" />
30+
<None Include="LICENSE.txt" Pack="true" PackagePath="" />
31+
<None Include="nuget\Icon.png" Pack="true" PackagePath="" />
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<PackageReference Include="Serilog" Version="4.0.0" />
36+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
37+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
38+
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.6" />
39+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
40+
</ItemGroup>
3741
</Project>

working/templates/dotnetToolProject/Program.cs

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
namespace $PackageId$
22
{
3+
using System;
34
using System.CommandLine;
45
using System.Threading.Tasks;
56

7+
using Microsoft.Extensions.Logging;
8+
9+
using Serilog;
10+
611
/// <summary>
712
/// $PackageDescription$.
813
/// </summary>
@@ -19,6 +24,15 @@ public static class Program
1924
/// <returns>0 if successful.</returns>
2025
public static async Task<int> Main(string[] args)
2126
{
27+
var isDebug = new Option<bool>(
28+
name: "--debug",
29+
description: "Indicates the tool should write out debug logging.")
30+
{
31+
IsRequired = false,
32+
};
33+
34+
isDebug.SetDefaultValue(false);
35+
2236
var exampleArgument = new Option<string>(
2337
name: "--example-argument",
2438
description: "Just an example argument.")
@@ -28,17 +42,42 @@ public static async Task<int> Main(string[] args)
2842

2943
var rootCommand = new RootCommand("$PackageDescription$")
3044
{
45+
isDebug,
3146
exampleArgument,
3247
};
3348

34-
rootCommand.SetHandler(Process, exampleArgument);
49+
rootCommand.SetHandler(Process, isDebug, exampleArgument);
3550

3651
return await rootCommand.InvokeAsync(args);
3752
}
3853

39-
private static async Task Process(string exampleArgument)
54+
private static async Task<int> Process(bool isDebug, string exampleArgument)
4055
{
41-
//Main Code for program here
56+
try
57+
{
58+
var logConfig = new LoggerConfiguration().WriteTo.Console();
59+
logConfig.MinimumLevel.Is(isDebug ? Serilog.Events.LogEventLevel.Debug : Serilog.Events.LogEventLevel.Information);
60+
var seriLog = logConfig.CreateLogger();
61+
62+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog));
63+
var logger = loggerFactory.CreateLogger("$PackageId$");
64+
try
65+
{
66+
//Main Code for program here
67+
}
68+
catch (Exception e)
69+
{
70+
logger.LogError($"Exception during Process Run: {e}");
71+
return 1;
72+
}
73+
}
74+
catch (Exception e)
75+
{
76+
Console.WriteLine($"Exception on Logger Creation: {e}");
77+
return 1;
78+
}
79+
80+
return 0;
4281
}
4382
}
4483
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
trim_trailing_whitespace = true
7+
8+
[*.csproj]
9+
indent_size = 2
10+
11+
[*.cs]
12+
dotnet_sort_system_directives_first = true
13+
dotnet_style_predefined_type_for_locals_parameters_members = true
14+
dotnet_style_predefined_type_for_member_access = false
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,41 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
<PropertyGroup>
3-
<OutputType>Exe</OutputType>
4-
<TargetFramework>net6.0</TargetFramework>
5-
<PackAsTool>true</PackAsTool>
6-
<ToolCommandName>$ToolCommandName$</ToolCommandName>
7-
<ImplicitUsings>disable</ImplicitUsings>
8-
<Nullable>disable</Nullable>
9-
<AssemblyName>$PackageId$</AssemblyName>
10-
<RootNamespace>$PackageId$</RootNamespace>
11-
<PackageVersion>1.0.1</PackageVersion>
12-
<Version>1.0.1</Version>
13-
<PackageTags>Skyline;DataMiner</PackageTags>
14-
<PackageProjectUrl>https://skyline.be</PackageProjectUrl>
15-
<PackageReadmeFile>README.md</PackageReadmeFile>
16-
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
17-
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
18-
<PackageIcon>Icon.png</PackageIcon>
19-
<GenerateDocumentationFile>True</GenerateDocumentationFile>
20-
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
21-
<Authors>SkylineCommunications</Authors>
22-
<Company>Skyline Communications</Company>
23-
<Description>$PackageDescription$</Description>
24-
<RepositoryType Condition="$(hasGitRepoUrl)">git</RepositoryType>
25-
<RepositoryUrl Condition="$(hasGitRepoUrl)">$GitRepoUrl$</RepositoryUrl>
26-
</PropertyGroup>
2+
<PropertyGroup>
3+
<OutputType>Exe</OutputType>
4+
<TargetFramework>net8.0</TargetFramework>
5+
<PackAsTool>true</PackAsTool>
6+
<ToolCommandName>$ToolCommandName$</ToolCommandName>
7+
<ImplicitUsings>disable</ImplicitUsings>
8+
<Nullable>disable</Nullable>
9+
<AssemblyName>$PackageId$</AssemblyName>
10+
<RootNamespace>$PackageId$</RootNamespace>
11+
<PackageVersion>1.0.1</PackageVersion>
12+
<Version>1.0.1</Version>
13+
<PackageTags>Skyline;DataMiner</PackageTags>
14+
<PackageProjectUrl>https://skyline.be</PackageProjectUrl>
15+
<PackageReadmeFile>README.md</PackageReadmeFile>
16+
<PackageLicenseFile>LICENSE.txt</PackageLicenseFile>
17+
<PackageRequireLicenseAcceptance>True</PackageRequireLicenseAcceptance>
18+
<PackageIcon>Icon.png</PackageIcon>
19+
<GenerateDocumentationFile>True</GenerateDocumentationFile>
20+
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
21+
<Authors>SkylineCommunications</Authors>
22+
<Company>Skyline Communications</Company>
23+
<Description>$PackageDescription$</Description>
24+
<RepositoryType Condition="$(hasGitRepoUrl)">git</RepositoryType>
25+
<RepositoryUrl Condition="$(hasGitRepoUrl)">$GitRepoUrl$</RepositoryUrl>
26+
</PropertyGroup>
2727

28-
<ItemGroup>
29-
<None Include="README.md" Pack="true" PackagePath="" />
30-
<None Include="LICENSE.txt" Pack="true" PackagePath="" />
31-
<None Include="nuget\Icon.png" Pack="true" PackagePath="" />
32-
</ItemGroup>
33-
<ItemGroup>
34-
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.3" />
35-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
36-
</ItemGroup>
28+
<ItemGroup>
29+
<None Include="README.md" Pack="true" PackagePath="" />
30+
<None Include="LICENSE.txt" Pack="true" PackagePath="" />
31+
<None Include="nuget\Icon.png" Pack="true" PackagePath="" />
32+
</ItemGroup>
33+
34+
<ItemGroup>
35+
<PackageReference Include="Serilog" Version="4.0.0" />
36+
<PackageReference Include="Serilog.Extensions.Logging" Version="8.0.0" />
37+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
38+
<PackageReference Include="Skyline.DataMiner.CICD.FileSystem" Version="1.0.6" />
39+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
40+
</ItemGroup>
3741
</Project>

working/templates/dotnetToolSolution/ClassLibrary1/Program.cs

+42-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
namespace $PackageId$
22
{
3+
using System;
34
using System.CommandLine;
45
using System.Threading.Tasks;
56

7+
using Microsoft.Extensions.Logging;
8+
9+
using Serilog;
10+
611
/// <summary>
712
/// $PackageDescription$.
813
/// </summary>
@@ -19,6 +24,15 @@ public static class Program
1924
/// <returns>0 if successful.</returns>
2025
public static async Task<int> Main(string[] args)
2126
{
27+
var isDebug = new Option<bool>(
28+
name: "--debug",
29+
description: "Indicates the tool should write out debug logging.")
30+
{
31+
IsRequired = false,
32+
};
33+
34+
isDebug.SetDefaultValue(false);
35+
2236
var exampleArgument = new Option<string>(
2337
name: "--example-argument",
2438
description: "Just an example argument.")
@@ -28,17 +42,42 @@ public static async Task<int> Main(string[] args)
2842

2943
var rootCommand = new RootCommand("$PackageDescription$")
3044
{
45+
isDebug,
3146
exampleArgument,
3247
};
3348

34-
rootCommand.SetHandler(Process, exampleArgument);
49+
rootCommand.SetHandler(Process, isDebug, exampleArgument);
3550

3651
return await rootCommand.InvokeAsync(args);
3752
}
3853

39-
private static async Task Process(string exampleArgument)
54+
private static async Task<int> Process(bool isDebug, string exampleArgument)
4055
{
41-
//Main Code for program here
56+
try
57+
{
58+
var logConfig = new LoggerConfiguration().WriteTo.Console();
59+
logConfig.MinimumLevel.Is(isDebug ? Serilog.Events.LogEventLevel.Debug : Serilog.Events.LogEventLevel.Information);
60+
var seriLog = logConfig.CreateLogger();
61+
62+
using var loggerFactory = LoggerFactory.Create(builder => builder.AddSerilog(seriLog));
63+
var logger = loggerFactory.CreateLogger("$PackageId$");
64+
try
65+
{
66+
//Main Code for program here
67+
}
68+
catch (Exception e)
69+
{
70+
logger.LogError($"Exception during Process Run: {e}");
71+
return 1;
72+
}
73+
}
74+
catch (Exception e)
75+
{
76+
Console.WriteLine($"Exception on Logger Creation: {e}");
77+
return 1;
78+
}
79+
80+
return 0;
4281
}
4382
}
4483
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
root = true
2+
3+
[*]
4+
indent_style = space
5+
indent_size = 4
6+
trim_trailing_whitespace = true
7+
8+
[*.csproj]
9+
indent_size = 2
10+
11+
[*.cs]
12+
dotnet_sort_system_directives_first = true
13+
dotnet_style_predefined_type_for_locals_parameters_members = true
14+
dotnet_style_predefined_type_for_member_access = false

0 commit comments

Comments
 (0)