Skip to content

Commit 9925d37

Browse files
Merge pull request #11623 from Mikejo5000/mikejo-br21
Switch to Vite from Vue CLI for ASP.NET Core app
2 parents c2bf77c + e740599 commit 9925d37

File tree

1 file changed

+30
-19
lines changed

1 file changed

+30
-19
lines changed

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

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: "Create an ASP.NET Core app with Vue"
33
description: In this tutorial, you create an app using ASP.NET Core and Vue
4-
ms.date: 04/25/2023
4+
ms.date: 08/23/2023
55
ms.topic: tutorial
66
ms.devlang: javascript
77
author: mikejo5000
@@ -28,20 +28,19 @@ 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**.
39-
- npm ([https://www.npmjs.com/](https://www.npmjs.com/package/npm)), which is included with Node.js
40-
- Vue CLI ([https://cli.vuejs.org/](https://cli.vuejs.org/))
39+
- npm ([https://www.npmjs.com/](https://www.npmjs.com/package/npm)), which is included with Node.js.
4140

4241
## Create the frontend app
4342

44-
1. In the Start window (choose **File** > **Start Window** to open), select **Create a new project**.
43+
1. In the Start window (choose **File** > **Start Window** to open), select **Create a new project**.
4544

4645
:::image type="content" source="media/vs-2022/create-new-project.png" alt-text="Screenshot showing Create a new project":::
4746

@@ -58,13 +57,13 @@ Make sure to install the following:
5857
Compared to the [standalone Vue template](../javascript/tutorial-create-vue-app.md), you see some new and modified files for integration with ASP.NET Core:
5958

6059
- aspnetcore-https.js
61-
- vue.config.json (modified)
60+
- vite.config.json (modified)
6261
- HelloWorld.vue (modified)
6362
- package.json (modified)
6463

6564
## Set the project properties
6665

67-
1. In Solution Explorer, right-click the ASP.NET Core project and choose **Properties**.
66+
1. In Solution Explorer, right-click the ASP.NET Core project (webapi) and choose **Properties**.
6867

6968
:::image type="content" source="media/vs-2022/asp-net-core-project-properties.png" alt-text="Screenshot showing Open project properties":::
7069

@@ -145,40 +144,52 @@ Starting in Visual Studio 2022 version 17.3, you can publish the integrated solu
145144
You may see the following error:
146145

147146
```
148-
[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)
147+
[HPM] Error occurred while trying to proxy request /weatherforecast from localhost:4200 to https://localhost:5173 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)
149148
```
150149

151150
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 Vue app in the browser.
152151

153-
Otherwise, if the port is in use, try 5002 in *launchSettings.json* and *vue.config.js*.
152+
Otherwise, if the port is in use, try incrementing the port number by **1** in *launchSettings.json* and *vite.config.js*.
153+
154+
### Privacy error
155+
156+
You may see the following certificate error:
157+
158+
```
159+
Your connection isn't private
160+
```
161+
162+
Try deleting the Vue certificates from *%appdata%\local\asp.net\https* or *%appdata%\roaming\asp.net\https*, and then retry.
154163

155164
### Verify ports
156165

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

159-
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.
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.
160169

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

163-
1. Then, go to the *vue.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:
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:
164173

165174
```js
166-
target: 'https://localhost:5001',
175+
url: 'https://localhost:5173',
167176
```
168177

178+
or:
179+
169180
### Outdated version of Vue
170181

171-
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 Vue CLI. After you update the Vue CLI, you may also need to delete the *.vuerc* file in *C:\Users\\[yourprofilename\]*.
182+
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\]*.
172183

173184
### Docker
174185

175-
If you enable Docker support while creating the web API project, the backend may start up using the Docker profile and not listen on the configured port 5001. To resolve:
186+
If you enable Docker support while creating the web API project, the backend may start up using the Docker profile and not listen on the configured port 5173. To resolve:
176187

177-
Edit the Docker profile in the launchSettings.json by adding the following properties:
188+
Edit the Docker profile in the *launchSettings.json* by adding the following properties:
178189

179190
```json
180-
"httpPort": 5003,
181-
"sslPort": 5001
191+
"httpPort": 5175,
192+
"sslPort": 5173
182193
```
183194

184195
Alternatively, reset using the following method:

0 commit comments

Comments
 (0)