Skip to content

Commit 665ec4a

Browse files
Merge pull request #11624 from Mikejo5000/mikejo-br21
Switch ASP.NET Core with React project to use Vite
2 parents dc03dd8 + aa791d2 commit 665ec4a

File tree

2 files changed

+24
-17
lines changed

2 files changed

+24
-17
lines changed

docs/javascript/tutorial-asp-net-core-with-react.md

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create an ASP.NET Core app with React"
33
description: In this tutorial, you create an app using ASP.NET Core and React
4-
ms.date: 04/25/2023
4+
ms.date: 08/24/2023
55
ms.topic: tutorial
66
ms.devlang: javascript
77
author: mikejo5000
@@ -28,13 +28,13 @@ You can use the method described in this article to create ASP.NET Core Single P
2828
- Create the client project based on the framework CLI installed on your computer
2929

3030
> [!NOTE]
31-
> A simplified, updated template is available starting in Visual Studio 2022 version 17.5. This template creates two projects in the initial solution and eliminates several configuration steps compared to the previous template. This article describes the project creation process using the new template.
31+
> A simplified, updated template is available starting in Visual Studio 2022 version 17.5. This template creates two projects in the initial solution and eliminates several configuration steps compared to the previous template. This article describes the project creation process using the template in Visual Studio 2022 version 17.7, which uses the Vite CLI.
3232
3333
## Prerequisites
3434

3535
Make sure to install the following:
3636

37-
- Visual Studio 2022 version 17.5 or later with the **ASP.NET and web development** workload installed. Go to the [Visual Studio downloads](https://visualstudio.microsoft.com/downloads/?cid=learn-onpage-download-cta) page to install it for free.
37+
- Visual Studio 2022 version 17.7 or later with the **ASP.NET and web development** workload installed. Go to the [Visual Studio downloads](https://visualstudio.microsoft.com/downloads/?cid=learn-onpage-download-cta) page to install it for free.
3838
If you need to install the workload and already have Visual Studio, go to **Tools** > **Get Tools and Features...**, which opens the Visual Studio Installer. Choose the **ASP.NET and web development** workload, then choose **Modify**.
3939
- npm ([https://www.npmjs.com/](https://www.npmjs.com/package/npm)), which is included with Node.js
4040
- npx ([https://www.npmjs.com/package/npx](https://www.npmjs.com/package/npx))
@@ -58,8 +58,7 @@ Make sure to install the following:
5858
Compared to the [standalone React template](../javascript/tutorial-create-react-app.md), you see some new and modified files for integration with ASP.NET Core:
5959

6060
- aspnetcore-https.js
61-
- aspnetcore-react.js
62-
- setupProxy.js
61+
- vite.config.js
6362
- App.js (modified)
6463
- App.test.js (modified)
6564

@@ -152,7 +151,7 @@ Starting in Visual Studio 2022 version 17.3, you can publish the integrated solu
152151
You may see the following error:
153152

154153
```cmd
155-
[HPM] Error occurred while trying to proxy request /weatherforecast from localhost:4200 to https://localhost:5001 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
154+
[HPM] Error occurred while trying to proxy request /weatherforecast from localhost:4200 to https://localhost:7183 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
156155
```
157156

158157
If you see this issue, most likely the frontend started before the backend. Once you see the backend command prompt up and running, just refresh the React App in the browser.
@@ -161,16 +160,26 @@ If you see this issue, most likely the frontend started before the backend. Once
161160

162161
If the weather data does not load correctly, you may also need to verify that your ports are correct.
163162

164-
1. Make sure that the port numbers match. Go to the *launchSettings.json* file in your ASP.NET Core project (in the *Properties* folder). Get the port number from the `applicationUrl` property.
163+
1. Make sure that the port numbers match. Go to the *launchSettings.json* file in your ASP.NET Core **webapi** project (in the *Properties* folder). Get the port number from the `applicationUrl` property.
165164

166-
If there are multiple `applicationUrl` properties, look for one using an `https` endpoint. It should look similar to `https://localhost:7049`.
165+
If there are multiple `applicationUrl` properties, look for one using an `https` endpoint. It should look similar to `https://localhost:7183`.
167166

168-
1. Then, go to the *setupProxy.js* file for your React project (look in the *src* folder). Update the target property to match the `applicationUrl` property in *launchSettings.json*. When you update it, that value should look similar to this:
167+
1. Then, go to the *vite.config.js* file for your React project. Update the `target` property to match the `applicationUrl` property in *launchSettings.json*. When you update it, that value should look similar to this:
169168

170169
```js
171-
target: 'https://localhost:7049',
170+
target: 'https://localhost:7183/',
172171
```
173172

173+
### Privacy error
174+
175+
You may see the following certificate error:
176+
177+
```
178+
Your connection isn't private
179+
```
180+
181+
Try deleting the React certificates from *%appdata%\local\asp.net\https* or *%appdata%\roaming\asp.net\https*, and then retry.
182+
174183
## Next steps
175184

176-
For more information about SPA applications in ASP.NET Core, see the React section under [Developing Single Page Apps](/aspnet/core/client-side/spa/intro#developing-single-page-apps). The linked article provides additional context for project files such as *aspnetcore-https.js*, *aspnetcore-react.js*, and *setupProxy.js*, although details of the implementation are different based on the template differences. For example, instead of a ClientApp folder, the React files are contained in a separate project.
185+
For more information about SPA applications in ASP.NET Core, see the React section under [Developing Single Page Apps](/aspnet/core/client-side/spa/intro#developing-single-page-apps). The linked article provides additional context for project files such as *aspnetcore-https.js*, although details of the implementation are different based on the template differences. For example, instead of a ClientApp folder, the React files are contained in a separate project.

docs/javascript/tutorial-asp-net-core-with-vue.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,18 +165,16 @@ Try deleting the Vue certificates from *%appdata%\local\asp.net\https* or *%appd
165165

166166
If the weather data does not load correctly, you may also need to verify that your ports are correct.
167167

168-
1. Make sure that the port numbers match. Go to the *launchSettings.json* file in your ASP.NET Core project (in the *Properties* folder). Get the port number from the `url` or `applicationUrl` property.
168+
1. Make sure that the port numbers match. Go to the *launchSettings.json* file in your ASP.NET Core **webapi** project (in the *Properties* folder). Get the port number from the `applicationUrl` property.
169169

170-
If there are multiple `url` or `applicationUrl` properties, look for one using an `https` endpoint. It should look similar to `https://localhost:5173`.
170+
If there are multiple `applicationUrl` properties, look for one using an `https` endpoint. It should look similar to `https://localhost:7142`.
171171

172-
1. Then, go to the *vite.config.js* file for your Vue project. Update the url or target property to match the `url` or `applicationUrl` property in *launchSettings.json*. When you update it, that value should look similar to this:
172+
1. Then, go to the *vite.config.js* file for your Vue project. Update the `target` property to match the `applicationUrl` property in *launchSettings.json*. When you update it, that value should look similar to this:
173173

174174
```js
175-
url: 'https://localhost:5173',
175+
target: 'https://localhost:7142/',
176176
```
177177

178-
or:
179-
180178
### Outdated version of Vue
181179

182180
If you see the console message **Could not find the file 'C:\Users\Me\source\repos\vueprojectname\package.json'** when you create the project, you may need to update your version of the Vite CLI. After you update the Vite CLI, you may also need to delete the *.vuerc* file in *C:\Users\\[yourprofilename\]*.

0 commit comments

Comments
 (0)