Skip to content

Commit 80a4ac6

Browse files
authored
Merge pull request #10 from drwatson1/net5
Support of Net 5.0 and .Net Core Project Template
2 parents 66a0c55 + dd9fb42 commit 80a4ac6

File tree

8 files changed

+106
-24
lines changed

8 files changed

+106
-24
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<PackageType>Template</PackageType>
5+
<PackageVersion>2.6</PackageVersion>
6+
<PackageId>DrWatson1.ProjectTemplate.RestAPI</PackageId>
7+
<Title>ASP.Net Core RESTful Service Template</Title>
8+
<Authors>Sergey Tregub</Authors>
9+
<Description>Project template to create production-ready RESTful service based on ASP.Net Core v3.1 or 5.0. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features</Description>
10+
<PackageTags>dotnet-new;templates;webapi;web;rest-api</PackageTags>
11+
<TargetFramework>netcoreapp3.1</TargetFramework>
12+
13+
<IncludeContentInPack>true</IncludeContentInPack>
14+
<IncludeBuildOutput>false</IncludeBuildOutput>
15+
<ContentTargetFolders>content</ContentTargetFolders>
16+
<NoWarn>$(NoWarn);NU5128</NoWarn>
17+
<PackageReleaseNotes>Support of .Net Core 5.0 and dotnet new custom template</PackageReleaseNotes>
18+
<PackageLicenseFile>LICENSE</PackageLicenseFile>
19+
<PackageProjectUrl>https://github.com/drwatson1/AspNet-Core-REST-Service</PackageProjectUrl>
20+
<RepositoryUrl>https://github.com/drwatson1/AspNet-Core-REST-Service</RepositoryUrl>
21+
<RepositoryType>GitHub</RepositoryType>
22+
</PropertyGroup>
23+
24+
<ItemGroup>
25+
<Content Include="ReferenceProject\**\*" Exclude="ReferenceProject\**\bin\**;ReferenceProject\**\obj\**" />
26+
<Compile Remove="**\*" />
27+
</ItemGroup>
28+
29+
<ItemGroup>
30+
<None Include="..\LICENSE">
31+
<Pack>True</Pack>
32+
<PackagePath></PackagePath>
33+
</None>
34+
</ItemGroup>
35+
36+
</Project>

ProjectTemplates/How to create new template.md renamed to ProjectTemplates/How to create a new template.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
After making any changes do:
44

5+
**Create a VSIX project template:**
56
1. Select Release configuration for a solution
67
1. Select ReferenceProject in "Solution Explorer" and click "Project/Export Template..." menu item from the VS main menu
78
1. In the appeared dialog box select "Project template" option and "ReferenceProject" in the combobox below and click Next
8-
1. Set the value `ASP.Net Core RESTful Service` as a template name and the `Project template to create production-ready RESTful service based on ASP.Net Core v3.1. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features` as a description
9+
1. Set the value `ASP.Net Core RESTful Service` as a template name and the `Project template to create production-ready RESTful service based on ASP.Net Core v3.1 or 5.0. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features` as a description
910
1. Don't foget to replace .Net Core version in the description above to the appropriate one.
1011
1. Clear checkbox "Automatically import the template into Visual Studio" if you don't want immediately import it and click Finish button
1112
1. Extract all files from the created zip-archive to any folder as you want. Typically, the file can be found in `C:\Users\<YOU>\Documents\Visual Studio 2019\My Exported Templates` folder
@@ -28,4 +29,16 @@ After making any changes do:
2829
1. Add Release Notes
2930
1. Rebuild the ReferenceProjectVSIX project and get "ASP.Net Core RESTful Service Template.vsix"
3031

32+
**Create a .Net Core Custom template**
33+
1. Open the `DrWatson1.ProjectTemplate.RestAPI.csproj`
34+
1. Update a package version in the `PackageVersion` tag
35+
1. Update a description in the `Description` tag when needed
36+
1. Update release notes in the `PackageReleaseNotes` tag
37+
1. Open a command prompt and go to the "ProjectTemplates" folder
38+
1. Execute the command:
39+
40+
```
41+
dotnet pack DrWatson1.ProjectTemplate.RestAPI.csproj -c Release
42+
```
43+
3144
That's all. "ASP.Net Core RESTful Service Template.vsix" can be uploaded to VS Marketplace or installed in VS.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"$schema": "http://json.schemastore.org/template",
3+
"author": "Sergey Tregub",
4+
"classifications": [ "Web", "WebAPI", "REST"],
5+
"name": "ASP.Net Core RESTful Service",
6+
"identity": "DrWatson1.ProjectTemplate.RestAPI",
7+
"groupIdentity": "DrWatson1.ProjectTemplate",
8+
"shortName": "rest-api",
9+
"tags": {
10+
"language": "C#",
11+
"type": "project"
12+
},
13+
"sourceName": "ReferenceProject",
14+
"preferNameDirectory": true
15+
}

ProjectTemplates/ReferenceProject/ReferenceProject.csproj

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,23 @@
3535
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="8.1.1" />
3636
<PackageReference Include="Contrib.Extensions.Configuration.AutoBind" Version="1.0.0" />
3737
<PackageReference Include="Contrib.Extensions.Configuration.VariablesSubstitution" Version="1.2.0" />
38-
<PackageReference Include="DotNetEnv" Version="2.1.0" />
38+
<PackageReference Include="DotNetEnv" Version="2.1.1" />
3939
<PackageReference Include="Microsoft.AspNet.WebApi.Client" Version="5.2.7" />
4040
<PackageReference Include="Serilog" Version="2.10.0" />
41-
<PackageReference Include="Serilog.AspNetCore" Version="3.4.0" />
41+
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0" />
4242
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.1.3" />
4343
<PackageReference Include="Serilog.Enrichers.Process" Version="2.0.1" />
4444
<PackageReference Include="Serilog.Enrichers.Thread" Version="3.1.0" />
45-
<PackageReference Include="Serilog.Exceptions" Version="6.0.0" />
46-
<PackageReference Include="Serilog.Expressions" Version="1.0.0" />
47-
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.0" />
45+
<PackageReference Include="Serilog.Exceptions" Version="6.1.0" />
46+
<PackageReference Include="Serilog.Expressions" Version="2.0.0" />
47+
<PackageReference Include="Serilog.Extensions.Hosting" Version="4.1.2" />
4848
<PackageReference Include="Serilog.Extensions.Logging" Version="3.0.1" />
4949
<PackageReference Include="Serilog.Formatting.Compact" Version="1.1.0" />
5050
<PackageReference Include="Serilog.Settings.Configuration" Version="3.1.0" />
5151
<PackageReference Include="Serilog.Sinks.Console" Version="3.1.1" />
5252
<PackageReference Include="Serilog.Sinks.File" Version="4.1.0" />
53-
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.0.7" />
54-
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.0.7" />
53+
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.1.4" />
54+
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="6.1.4" />
5555
<PackageReference Include="System.Net.Http" Version="4.3.4" />
5656
</ItemGroup>
5757

ProjectTemplates/ReferenceProject/Startup.cs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
* Getting started guide: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki/Getting-Started-Guide
3030
* More information about configuring project: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki
3131
*/
32-
3332
namespace ReferenceProject
3433
{
3534
public class Startup
3635
{
36+
IConfiguration Configuration { get; }
37+
IHostEnvironment HostEnvironment { get; }
38+
3739
public Startup(IConfiguration configuration, IHostEnvironment env)
3840
{
39-
Startup.Configuration = configuration;
41+
Configuration = configuration;
42+
HostEnvironment = env;
4043

4144
// See: https://github.com/drwatson1/AspNet-Core-REST-Service/wiki#content-formatting
4245
JsonConvert.DefaultSettings = () =>
@@ -47,19 +50,13 @@ public Startup(IConfiguration configuration, IHostEnvironment env)
4750
NullValueHandling = NullValueHandling.Ignore,
4851
DefaultValueHandling = DefaultValueHandling.Include,
4952
ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
50-
#if DEBUG
51-
Formatting = Formatting.Indented
52-
#else
53-
Formatting = Formatting.None
54-
#endif
53+
Formatting = env.IsDevelopment() ? Formatting.Indented : Formatting.None
5554
};
5655
settings.Converters.Add(new StringEnumConverter { CamelCaseText = true });
5756
return settings;
5857
};
5958
}
6059

61-
public static IConfiguration Configuration { get; private set; }
62-
6360
// This method gets called by the runtime. Use this method to add services to the container.
6461
public void ConfigureServices(IServiceCollection services)
6562
{
@@ -82,6 +79,7 @@ public void ConfigureServices(IServiceCollection services)
8279
options.JsonSerializerOptions.IgnoreNullValues = true;
8380
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter(JsonNamingPolicy.CamelCase));
8481
options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
82+
options.JsonSerializerOptions.WriteIndented = HostEnvironment.IsDevelopment();
8583
})
8684
.AddApiExplorer()
8785
.SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

ProjectTemplates/ReferenceProjectVSIX/source.extension.vsixmanifest

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<PackageManifest Version="2.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
33
<Metadata>
4-
<Identity Id="ASP.Net Core RESTful Service Template-1" Version="2.5" Language="en-US" Publisher="Sergey Tregub" />
5-
<DisplayName>ASP.Net Core 3.1 RESTful Service Template</DisplayName>
6-
<Description xml:space="preserve">Project template to create production-ready RESTful service based on ASP.Net Core 3.1. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features</Description>
4+
<Identity Id="ASP.Net Core RESTful Service Template-1" Version="2.6" Language="en-US" Publisher="Sergey Tregub" />
5+
<DisplayName>ASP.Net Core 3.1/5.0 RESTful Service Template</DisplayName>
6+
<Description xml:space="preserve">Project template to create production-ready RESTful service based on ASP.Net Core 3.1 or 5.0. It contains preconfigured DI-container, logging, CORS, some boilerplate code and other features</Description>
77
<MoreInfo>https://github.com/drwatson1/AspNet-Core-REST-Service</MoreInfo>
88
<GettingStartedGuide>https://github.com/drwatson1/AspNet-Core-REST-Service/wiki</GettingStartedGuide>
9-
<ReleaseNotes>Minor fixes</ReleaseNotes>
9+
<ReleaseNotes>Support of .Net Core 5.0 and dotnet new custom template</ReleaseNotes>
1010
<Icon>Assets\logo.png</Icon>
11-
<Tags>asp-net-core restful-api vs2017 vs2019 visual-studio project-template</Tags>
11+
<Tags>asp-net-core restful-api vs2017 vs2019 visual-studio project-template web-api</Tags>
1212
</Metadata>
1313
<Installation>
1414
<InstallationTarget Id="Microsoft.VisualStudio.Community" Version="[15.0, 17.0)" />

README.md

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ASP.Net Core RESTful Service Template
22

3-
The repository contains a ready to use preconfigured project template for MS Visual Studio 2017 and 2019 to create fully functional production-ready cross-platform RESTful services based on ASP.Net Core 3.1.
3+
The repository contains a ready to use preconfigured project template for MS Visual Studio 2017 and 2019 to create fully functional production-ready cross-platform RESTful services based on ASP.Net Core 3.1/5.0.
44

55
> Note 1. ASP.NET Core 3.0 has many breaking changes against version 2.2. If you want to use v2.2 or earlier, please, check out one of the previous releases, starting from [version 1.3](https://github.com/drwatson1/AspNet-Core-REST-Service/releases/tag/v1.3) or earlier.
66
>
@@ -24,7 +24,7 @@ Let me know, what do you think. Any suggestions and bug reports are very appreci
2424

2525
# Getting Started
2626

27-
27+
## Using Visual Studio
2828
1. Install the extension from [Visual Studio Marketplace](https://marketplace.visualstudio.com/items?itemName=sergey-tregub.asp-net-core-restful-service-template#overview) or download and install the latest version from [GitHub](https://github.com/drwatson1/AspNet-Core-REST-Service/releases/latest). Also, you can install it from Visual Studio. To do so click on "Tools/Extensions and Updates..." menu item, then select "Online/Visual Studio Marketplace/Templates" on the left pane, search for "ASP.Net Core RESTful Service Template," select it and click "Download" button. Please note! The latest version of the template is targeted to the .Net Core 3.1. If you need a template for 2.x version use one of the previous version of the template.
2929
1. Restart Visual Studio
3030
1. Click on "File/New Project..." menu item
@@ -34,6 +34,25 @@ Let me know, what do you think. Any suggestions and bug reports are very appreci
3434
1. Open a browser and navigate to [http://localhost:5000/swagger](http://localhost:5000/swagger) to see an API documentation
3535
1. Play around with the API. Try to add a new product or update one
3636

37+
## Using command line
38+
39+
1. Install the template:
40+
```
41+
dotnet new -i DrWatson1.ProjectTemplate.RestAPI
42+
```
43+
2. Create a project:
44+
```
45+
dotnet new rest-api -n ASPNetCoreService
46+
```
47+
It creates a new project "ASPNetCoreService" in the corresponding subfolder.
48+
Replace the "ASPNetCoreService" with a desired name.
49+
3. Run the project:
50+
```
51+
dotnet run
52+
```
53+
4. Open a browser and navigate to [http://localhost:5000/swagger](http://localhost:5000/swagger) to see an API documentation
54+
5. Play around with the API. Try to add a new product or update one
55+
3756
Visit project [Wiki](https://github.com/drwatson1/AspNet-Core-REST-Service/wiki) pages to learn more about the template.
3857

3958
Have fun and happy hacking!
@@ -42,6 +61,7 @@ Have fun and happy hacking!
4261

4362
|Date | Version | Release Notes |
4463
|-----|---------|---------------|
64+
|2021-05-03|2.6|<p>- Support of .Net 5.0<p>- Add `dotnet new` custom template
4565
|2021-03-07|2.5|<p>- Minor fixes |
4666
|2021-02-27|2.4|<p>- Improve logging |
4767
|2021-02-23|2.3|<p>- Load .env before Serilog initialization to make it possible to use environment variables in Serilog configuration options<p>- Catch and log unhandled exceptions <p>- Update NuGet packages to the latest versions|

0 commit comments

Comments
 (0)