Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add templates for dotnet version 7 #237

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
469 changes: 469 additions & 0 deletions csharp/dotnet7/.gitignore

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>

<IsPackable>false</IsPackable>

<LangVersion>11</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.0">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.7.2" />
<PackageReference Include="xunit" Version="2.5.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\DotnetStarter.Logic\DotnetStarter.Logic.csproj"/>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage(
"Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
Justification = "Unit test naming follows https://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html",
Scope = "namespaceanddescendants", Target = "~N:DotnetStarter.Logic.Tests")]
9 changes: 9 additions & 0 deletions csharp/dotnet7/DotnetStarter.Logic.Tests/HelloWorldTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using Xunit;

namespace DotnetStarter.Logic.Tests;

public class HelloWorldTest
{
[Fact]
public void Hello_ReturnsWorld() => Assert.Equal("World!", HelloWorld.Hello());
}
8 changes: 8 additions & 0 deletions csharp/dotnet7/DotnetStarter.Logic/DotnetStarter.Logic.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>11</LangVersion>
</PropertyGroup>

</Project>
6 changes: 6 additions & 0 deletions csharp/dotnet7/DotnetStarter.Logic/HelloWorld.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace DotnetStarter.Logic;

public static class HelloWorld
{
public static string Hello() => "World!";
}
58 changes: 58 additions & 0 deletions csharp/dotnet7/DotnetStarter.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31911.196
MinimumVisualStudioVersion = 15.0.26124.0
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetStarter.Logic", "DotnetStarter.Logic\DotnetStarter.Logic.csproj", "{4F054F47-9777-4E9B-AC7D-803A3539ED29}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DotnetStarter.Logic.Tests", "DotnetStarter.Logic.Tests\DotnetStarter.Logic.Tests.csproj", "{5EC6F230-F709-49F1-97A5-0482B48719E7}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "misc", "misc", "{7CF31C68-F031-4F2B-B00A-D7A8C8C37D81}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|x64.ActiveCfg = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|x64.Build.0 = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|x86.ActiveCfg = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Debug|x86.Build.0 = Debug|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|Any CPU.Build.0 = Release|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|x64.ActiveCfg = Release|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|x64.Build.0 = Release|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|x86.ActiveCfg = Release|Any CPU
{4F054F47-9777-4E9B-AC7D-803A3539ED29}.Release|x86.Build.0 = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|x64.ActiveCfg = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|x64.Build.0 = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|x86.ActiveCfg = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Debug|x86.Build.0 = Debug|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|Any CPU.Build.0 = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|x64.ActiveCfg = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|x64.Build.0 = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|x86.ActiveCfg = Release|Any CPU
{5EC6F230-F709-49F1-97A5-0482B48719E7}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DCB8F894-FC57-4819-81E4-59C984EA02E5}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions csharp/dotnet7/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any
means.

In jurisdictions that recognize copyright laws, the author or authors
of this software dedicate any and all copyright interest in the
software to the public domain. We make this dedication for the benefit
of the public at large and to the detriment of our heirs and
successors. We intend this dedication to be an overt act of
relinquishment in perpetuity of all present and future rights to this
software under copyright law.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to <https://unlicense.org>
96 changes: 96 additions & 0 deletions csharp/dotnet7/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
# Starter Template for new .NET Projects

This repository provides a starter template for new C# projects.

## Development

### What is inside?

- DotnetStarter.Logic - is a DLL project for business logic
- DotnetStarter.Logic.Tests - is the corresponding xUnit test project, configured with static code rules allowing
underscores in test names (GlobalSuppressions.cs)

### Prerequisites

To compile, test and run this project the latest [.NET Core SDK](https://dotnet.microsoft.com/download) is required on
your machine. For calculating code metrics I recommend [metrix++](https://github.com/metrixplusplus/metrixplusplus).
This requires python.

If you are interested in test coverage, then you'll need the following tools installed:

```shell
dotnet tool install --global coverlet.console --configfile NuGet-OfficialOnly.config
dotnet tool install --global dotnet-reportgenerator-globaltool --configfile NuGet-OfficialOnly.config
```

## Build, Test, Run

Run the following commands from the folder containing the `.sln` file in order to build and test.

### Build the Solution and Run the Tests

```sh
dotnet build
dotnet test

# If you like continuous testing then use the dotnet file watcher to trigger your tests
dotnet watch --project ./DotnetStarter.Logic.Tests test

# As an alternative, run the tests with coverage and produce a coverage report
rm -r DotnetStarter.Logic.Tests/TestResults && \
dotnet test --no-restore --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput='./TestResults/coverage.cobertura.xml' && \
reportgenerator "-reports:DotnetStarter.Logic.Tests/TestResults/*.xml" "-targetdir:report" "-reporttypes:Html;lcov" "-title:DotnetStarter"
open report/index.html
```

### Apply code formatting rules

```shell
dotnet format
```

### Check Code Metrics

... check code metrics using [metrix++](https://github.com/metrixplusplus/metrixplusplus)

- Configure the location of the cloned metrix++ scripts
```shell
export METRIXPP=/path/to/metrixplusplus
```

- Collect metrics
```shell
python "$METRIXPP/metrix++.py" collect --std.code.complexity.cyclomatic --std.code.lines.code --std.code.todo.comments --std.code.maintindex.simple -- .
```

- Get an overview
```shell
python "$METRIXPP/metrix++.py" view --db-file=./metrixpp.db
```

- Apply thresholds
```shell
python "$METRIXPP/metrix++.py" limit --db-file=./metrixpp.db --max-limit=std.code.complexity:cyclomatic:5 --max-limit=std.code.lines:code:25:function --max-limit=std.code.todo:comments:0 --max-limit=std.code.mi:simple:1
```

At the time of writing, I want to stay below the following thresholds:

```text
--max-limit=std.code.complexity:cyclomatic:5
--max-limit=std.code.lines:code:25:function
--max-limit=std.code.todo:comments:0
--max-limit=std.code.mi:simple:1
```

### Remove Code Duplication Where Appropriate

To detect duplicates I use the [CPD Copy Paste Detector](https://pmd.github.io/latest/pmd_userdocs_cpd.html)
tool from the [PMD Source Code Analyzer Project](https://pmd.github.io/latest/index.html).

If you have installed PMD by download & unzip, replace `pmd` by `./run.sh`.
The [homebrew pmd formula](https://formulae.brew.sh/formula/pmd) makes the `pmd` command globally available.

```sh
pmd cpd --minimum-tokens 50 --language cs --files .
```

Loading