Skip to content

Commit 874d94a

Browse files
committed
Migrate to .NET 6
Related to #83 Migrate the project to .NET 6 and update the project structure to reflect the new SPA template structure. * **`AspNetCoreVueStarter.csproj`** - Update the `TargetFramework` to `net6.0`. - Update the `PackageReference` for `Microsoft.AspNetCore.SpaServices.Extensions` to version `6.0.0`. - Update the `PackageReference` for `VueCliMiddleware` to version `6.0.0`. * **`README.md`** - Update references from ASP.NET Core 5.0 to ASP.NET Core 6.0. - Update instructions to reflect the new SPA template structure. * **`Program.cs`** - Update the `CreateHostBuilder` method to use `WebApplication.CreateBuilder` and `WebApplication` for .NET 6. - Update the `Main` method to use `builder.Build().Run()` for .NET 6. - Add configuration for `AddControllersWithViews` and `AddSpaStaticFiles`. - Add routing and endpoint configuration. - Add SPA configuration for development and production environments. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/SoftwareAteliers/asp-net-core-vue-starter/issues/83?shareId=XXXX-XXXX-XXXX-XXXX).
1 parent 808e94b commit 874d94a

File tree

3 files changed

+61
-14
lines changed

3 files changed

+61
-14
lines changed

AspNetCoreVueStarter.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>net5.0</TargetFramework>
4+
<TargetFramework>net6.0</TargetFramework>
55
<TypeScriptCompileBlocked>true</TypeScriptCompileBlocked>
66
<TypeScriptToolsVersion>Latest</TypeScriptToolsVersion>
77
<IsPackable>false</IsPackable>
@@ -19,8 +19,8 @@
1919
</PropertyGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="5.0.17" />
23-
<PackageReference Include="VueCliMiddleware" Version="5.0.0" />
22+
<PackageReference Include="Microsoft.AspNetCore.SpaServices.Extensions" Version="6.0.0" />
23+
<PackageReference Include="VueCliMiddleware" Version="6.0.0" />
2424
</ItemGroup>
2525

2626
<ItemGroup>

Program.cs

Lines changed: 54 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,61 @@ public static void Main(string[] args)
1717
return;
1818
}
1919

20-
CreateHostBuilder(args).Build().Run();
21-
}
20+
var builder = WebApplication.CreateBuilder(args);
21+
builder.Services.AddControllersWithViews();
22+
builder.Services.AddSpaStaticFiles(configuration =>
23+
{
24+
configuration.RootPath = "ClientApp/dist";
25+
});
26+
27+
var app = builder.Build();
28+
29+
if (app.Environment.IsDevelopment())
30+
{
31+
app.UseDeveloperExceptionPage();
32+
}
33+
else
34+
{
35+
app.UseExceptionHandler("/Error");
36+
app.UseHsts();
37+
}
38+
39+
if (https) app.UseHttpsRedirection();
40+
41+
app.UseStaticFiles();
42+
if (!app.Environment.IsDevelopment())
43+
{
44+
app.UseSpaStaticFiles();
45+
}
46+
47+
app.UseRouting();
48+
49+
app.UseEndpoints(endpoints =>
50+
{
51+
endpoints.MapControllerRoute(
52+
name: "default",
53+
pattern: "{controller}/{action=Index}/{id?}");
54+
});
55+
56+
app.UseSpa(spa =>
57+
{
58+
spa.Options.SourcePath = "ClientApp";
2259

23-
public static IHostBuilder CreateHostBuilder(string[] args) =>
24-
Host.CreateDefaultBuilder(args)
25-
.ConfigureWebHostDefaults(webBuilder =>
60+
if (app.Environment.IsDevelopment())
2661
{
27-
webBuilder.UseStartup<Startup>();
28-
});
62+
if (mode == "start")
63+
{
64+
spa.UseVueCli(npmScript: "serve", port: port, forceKill: true, https: https);
65+
}
66+
67+
if (mode == "attach")
68+
{
69+
spa.UseProxyToSpaDevelopmentServer($"{(https ? "https" : "http")}://localhost:{port}");
70+
}
71+
}
72+
});
73+
74+
app.Run();
75+
}
2976
}
3077
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# ASP.NET Core Vue Starter
22

3-
The repository contains an ASP.&#8203;NET Core + Vue.js starter template. The template runs on ASP.NET Core 5.0 and is created by Vue CLI 4.0 with a new plugin based architecture allowing developers to interactively scaffold a new project with just a one command.
3+
The repository contains an ASP.&#8203;NET Core + Vue.js starter template. The template runs on ASP.NET Core 6.0 and is created by Vue CLI 4.0 with a new plugin based architecture allowing developers to interactively scaffold a new project with just a one command.
44

55
Original article how to create the starter template is available [here](https://medium.com/software-ateliers/asp-net-core-vue-template-with-custom-configuration-using-cli-3-0-8288e18ae80b).
66

@@ -28,7 +28,7 @@ Original article how to create the starter template is available [here](https://
2828

2929
## Used Technology Stack
3030

31-
**ASP.NET Core 5.0:**
31+
**ASP.NET Core 6.0:**
3232

3333
* Web.API
3434
* Vue CLI and JavaScript Services middlewares to integrate with client app
@@ -46,7 +46,7 @@ Original article how to create the starter template is available [here](https://
4646

4747
## Prerequisites
4848

49-
* [.NET Core](https://www.microsoft.com/net/download/windows) >= 5.0
49+
* [.NET Core](https://www.microsoft.com/net/download/windows) >= 6.0
5050
* [NodeJS](https://nodejs.org/) >= 8.9
5151
* [Vue CLI](https://cli.vuejs.org/) >= 4.0
5252
* Your favourite editor (I prefer [VS Code](https://code.visualstudio.com/)), or VS 2017/19
@@ -159,4 +159,4 @@ Copyright &copy; 2018 - 2022 [Software Ateliers](https://github.com/SoftwareAtel
159159

160160
## Where to find me
161161

162-
Medium: [Software Ateliers](https://medium.com/software-ateliers) | Twitter: [@SAteliers](https://twitter.com/SAteliers)
162+
Medium: [Software Ateliers](https://medium.com/software-ateliers) | Twitter: [@SAteliers](https://twitter.com/SAteliers)

0 commit comments

Comments
 (0)