Skip to content

HansKindberg/DotNet-Solution-Templates

Repository files navigation

DotNet-Solution-Templates

A template-package (NuGet) for creating solutions, with one or more projects, in dotnet / Visual Studio.

For the moment, because of an issue, the templates are not enabled in Visual Studio. See: Template.Source.json

NuGet

1 Using the templates

1.1 Install

dotnet new install HansKindberg-DotNet-Solution-Templates

or (if testing locally)

dotnet new install HansKindberg-DotNet-Solution-Templates --nuget-source "C:\Data\Projects\HansKindberg\DotNet-Solution-Templates\Source\Templates\bin\Debug"

or (if the package is in another nuget source)

dotnet new install HansKindberg-DotNet-Solution-Templates --nuget-source "https://nuget.example.org/v3/index.json"

1.2 Uninstall

dotnet new uninstall HansKindberg-DotNet-Solution-Templates

3 Development

I am using Visual Studio 2022 - 17.8.3 when starting this project.

This project/solution was initially created with:

dotnet new templatepack -n "Templates"

To have "templatepack" you need to install Microsoft.TemplateEngine.Authoring.Templates:

dotnet new install Microsoft.TemplateEngine.Authoring.Templates

3.1 Adjustments

After creating the project with:

dotnet new templatepack -n "Templates"

I had to do some adjustments:

<Project Sdk="Microsoft.NET.Sdk">
	<PropertyGroup>
		...
		<GeneratePackageOnBuild>true</GeneratePackageOnBuild><!-- Added this row. -->
		...
		<SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking><!-- Added this row. -->
		...
	</PropertyGroup>
	...
	<ItemGroup>
		...
		<Content Include="content\**\*" Exclude="content\**\bin\**;content\**\obj\**">
			<PackagePath>content</PackagePath><!-- Added this row. -->
		</Content>
		...
	</ItemGroup>
	...
</Project>

Got help by looking at:

3.2 Install / uninstall

How to install/uninstall during development.

3.2.1 Locally built NuGet-package

cd to Source\Templates\bin\Debug.

Install:

dotnet new install HansKindberg-DotNet-Solution-Templates.0.0.1.nupkg

Uninstall:

dotnet new uninstall HansKindberg-DotNet-Solution-Templates

3.2.2 Local folder

Install:

dotnet new install <PATH>

Uninstall:

dotnet new uninstall <PATH>

Where <PATH> is the path to the folder containing .template.config.

3.3 Try the templates

cd to your project directory.

dotnet new hk-aspnet-razor-l --name hk-aspnet-razor-l

dotnet new hk-aspnet-razor-m --name hk-aspnet-razor-m

dotnet new hk-aspnet-razor-s --name hk-aspnet-razor-s

dotnet new hk-aspnet-razor-xl --name hk-aspnet-razor-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

dotnet new hk-blazor-l --name hk-blazor-l

dotnet new hk-blazor-m --name hk-blazor-m

dotnet new hk-blazor-s --name hk-blazor-s

dotnet new hk-blazor-xl --name hk-blazor-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

dotnet new hk-blazor-duende-l --name hk-blazor-duende-l

dotnet new hk-blazor-duende-m --name hk-blazor-duende-m

dotnet new hk-blazor-duende-s --name hk-blazor-duende-s

dotnet new hk-blazor-duende-xl --name hk-blazor-duende-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

dotnet new hk-nuget-package-l --name hk.nuget.package.l

dotnet new hk-nuget-package-m --name hk.nuget.package.m

dotnet new hk-nuget-package-s --name hk.nuget.package.s

dotnet new hk-nuget-package-xl --name hk.nuget.package.xl

dotnet new hk-react-l --name hk-react-l

dotnet new hk-react-m --name hk-react-m

dotnet new hk-react-s --name hk-react-s

dotnet new hk-react-xl --name hk-react-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

dotnet new hk-react-duende-l --name hk-react-duende-l

dotnet new hk-react-duende-m --name hk-react-duende-m

dotnet new hk-react-duende-s --name hk-react-duende-s

dotnet new hk-react-duende-xl --name hk-react-duende-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

dotnet new hk-service-l --name hk-service-l

dotnet new hk-service-m --name hk-service-m

dotnet new hk-service-s --name hk-service-s

dotnet new hk-service-xl --name hk-service-xl --directTemplateProcessing false/true --kubernetesImageRegistry false/true

3.4 Important

We have experienced problems when the solution-files included in the templates are not UTF-8-BOM encoded. If we make changes in the *.sln files we should verify that they are UTF-8-BOM encoded. If not, make them UTF-8-BOM encoded with Notepadd++ for example.

This seems to happen even if we have this in .editorconfig:

[*.{cshtml,sln}]
charset = utf-8-bom

3.5 Links

4 Tests

There is a lot of "IO" in the integration-tests. Making the tests run sequential helps:

If we run the tests in parallel we often get failing tests.

5 Thanks Damien Bowden

His article/work led me the way to build "solution"-templates:

6 Links