Skip to content

Commit 3577209

Browse files
committed
Upgrade blazor to .net 5.0
1 parent c0441bb commit 3577209

File tree

11 files changed

+44
-76
lines changed

11 files changed

+44
-76
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ This demo shows how React apps can live together with Blazor apps, which are bas
44

55
## Getting started
66

7-
To configure Blazor on your machine, you can follow the [instructions](https://docs.microsoft.com/en-us/aspnet/core/blazor/get-started) online. For the rest, you only need:
7+
To configure Blazor on your machine, you can follow the [instructions](https://dotnet.microsoft.com/apps/aspnet/web-apps/blazor) online. For the rest, you only need:
88

99
```
1010
npm install
1111
```
1212

1313
### Build
1414

15-
To build the project and run it locally, run
15+
To build the project and run it locally run
1616

1717
```
1818
npm run build
1919
npm start
2020
```
2121

22-
The later will create a web site at `http://localhost:8080/react-blazor/`.
22+
Then you can access it at `http://localhost:8080/react-blazor/`.
2323

2424
## Questions & contribution
2525

26-
You can follow me on Twitter with [@boyanio](https://twitter.com/boyanio) and ask me questions you might have. You can also open an issue here on GitHub. Pull requests are welcome, too :-)
26+
You can follow me on Twitter [@boyanio](https://twitter.com/boyanio) and ask me any questions you might have. You can also open an issue here on GitHub. Pull Requests are welcome too :-)

blazor-output.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
const { promisify } = require('util');
22
const fs = require('fs');
33
const rimraf = require('rimraf');
4-
const ncp = require('ncp').ncp;
4+
const { ncp } = require('ncp');
55

66
const fsAsync = ['exists', 'mkdir']
77
.reduce((value, func) => Object.assign(value, { [func]: promisify(fs[func]) }), {});
88
const rimrafAsync = promisify(rimraf);
99
const ncpAsync = promisify(ncp);
1010

1111
const run = async (buildConfiguration) => {
12-
const publishDir = `${__dirname}/src/blazor/BlazorChatApp/bin/${buildConfiguration}/netstandard2.0/publish/BlazorChatApp/dist`;
1312
const buildDir = `${__dirname}/build/apps/blazor`;
1413

1514
if (await fsAsync.exists(buildDir)) {
@@ -18,6 +17,7 @@ const run = async (buildConfiguration) => {
1817

1918
await fsAsync.mkdir(buildDir);
2019

20+
const publishDir = `${__dirname}/src/blazor/BlazorChatApp/bin/${buildConfiguration}/net5.0/publish/wwwroot`;
2121
await ncpAsync(`${publishDir}/_framework`, `${buildDir}/_framework`);
2222
};
2323

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
],
1010
"scripts": {
1111
"build:react": "webpack",
12-
"build:blazor": "dotnet publish src/blazor/BlazorChatApp.sln -c Release && node blazor-output.js Release",
12+
"build:blazor": "dotnet publish src/blazor/BlazorChatApp/BlazorChatApp.csproj -c Release && node blazor-output.js Release",
1313
"build": "npm run build:react && npm run build:blazor",
1414
"start": "node serve.js"
1515
},

src/blazor/BlazorChatApp.sln

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/blazor/BlazorChatApp/App.razor

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1-
<Router AppAssembly="typeof(Program).Assembly">
2-
<NotFoundContent>
3-
<p>Sorry, there's nothing at this address.</p>
4-
</NotFoundContent>
1+
<Router AppAssembly="@typeof(Program).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
4+
</Found>
5+
<NotFound>
6+
<LayoutView Layout="@typeof(MainLayout)">
7+
<p>Sorry, there's nothing at this address.</p>
8+
</LayoutView>
9+
</NotFound>
510
</Router>
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>netstandard2.0</TargetFramework>
5-
<LangVersion>7.3</LangVersion>
6-
<RazorLangVersion>3.0</RazorLangVersion>
4+
<TargetFramework>net5.0</TargetFramework>
75
</PropertyGroup>
86

97
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Blazor" Version="3.0.0-preview8.19405.7" />
11-
<PackageReference Include="Microsoft.AspNetCore.Blazor.Build" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor.DevServer" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
13-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="3.0.0-preview8.19405.7" PrivateAssets="all" />
8+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.0" />
9+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.0" PrivateAssets="all" />
10+
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" />
1411
</ItemGroup>
1512

1613
</Project>
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
using Microsoft.AspNetCore.Blazor.Hosting;
1+
using BlazorChatApp.Core;
2+
using System.Threading.Tasks;
3+
using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
4+
using Microsoft.Extensions.DependencyInjection;
25

36
namespace BlazorChatApp
47
{
58
public class Program
69
{
7-
public static IWebAssemblyHostBuilder CreateHostBuilder(string[] args) =>
8-
BlazorWebAssemblyHost.CreateDefaultBuilder()
9-
.UseBlazorStartup<Startup>();
10-
11-
public static void Main(string[] args)
10+
public static async Task Main(string[] args)
1211
{
13-
CreateHostBuilder(args).Build().Run();
12+
var builder = WebAssemblyHostBuilder.CreateDefault(args);
13+
builder.RootComponents.Add<App>("#blazor-app");
14+
builder.Services.AddSingleton<ChatMessageRepository>();
15+
16+
await builder.Build().RunAsync();
1417
}
1518
}
16-
}
19+
}

src/blazor/BlazorChatApp/Shared/NewChatMessage.razor

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<form class="new-message-form">
44
<div class="row">
55
<div class="col-md-9">
6-
<input type="text" id="newChatMessage" class="form-control" placeholder="Enter your message here..." @bind="_newMessage" />
6+
<input type="text" class="form-control" placeholder="Enter your message here..." @bind="newMessage" />
77
</div>
88
<div class="col-md-3">
99
<button type="button" class="btn btn-primary btn-block" @onclick="AddChatMessageAsync">Send</button>
@@ -12,11 +12,16 @@
1212
</form>
1313

1414
@code {
15-
private string _newMessage = null;
15+
private string newMessage = null;
1616

17-
private async Task AddChatMessageAsync()
17+
private async Task AddChatMessageAsync(MouseEventArgs e)
1818
{
19-
await ChatMessageRepository.AddChatMessageAsync(new ChatMessage { Time = DateTime.Now, From = "Blazor", Text = _newMessage });
20-
_newMessage = null;
19+
await ChatMessageRepository.AddChatMessageAsync(new ChatMessage
20+
{
21+
Time = DateTime.Now,
22+
From = "Blazor",
23+
Text = newMessage
24+
});
25+
newMessage = null;
2126
}
2227
}

src/blazor/BlazorChatApp/Startup.cs

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/blazor/BlazorChatApp/_Imports.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@using System.Net.Http
33
@using Microsoft.AspNetCore.Components.Forms
44
@using Microsoft.AspNetCore.Components.Routing
5+
@using Microsoft.AspNetCore.Components.Web
56
@using Microsoft.JSInterop
67
@using BlazorChatApp
78
@using BlazorChatApp.Core

0 commit comments

Comments
 (0)