I used to be studying Gabby’s blog post about the new TypeScript/JavaScript project experience in Visual Studio 2022. It’s best to learn the docs on JavaScript and TypeScript in Visual Studio 2022.
For those who’re used to ASP.NET apps when you concentrate on apps which can be JavaScript heavy, “entrance finish apps” or TypeScript centered, it may be complicated as to “the place does .NET slot in?”
That you must contemplate the obligations of your numerous initiatives or subsystems and the a number of completely legitimate methods you possibly can construct a website or net app. Let’s contemplate just some:
- An ASP.NET Web app that renders HTML on the server but uses TS/JS
- This may increasingly have a Internet API, Razor Pages, with or with out the MVC sample.
- You possibly have simply added JavaScript by way of <script> tags
- Possibly you added a script minimizer/minifier job
- May be complicated as a result of it could possibly really feel like your app must ‘construct each the shopper and the server’ from one mission
- A largely JavaScript/TypeScript frontend app the place the HTML could possibly be served from any net server (node, kestrel, static net apps, nginx, and so forth)
- This app could use Vue or React or Angular but it surely’s not an “ASP.NET app”
- It calls backend Internet APIs that could be served by ASP.NET, Azure Capabilities, third social gathering REST APIs, or the entire above
- This situation has generally been complicated for ASP.NET builders who could get confused about duty. Who builds what, the place do issues find yourself, how do I construct and deploy this?
VS2022 brings JavaScript and TypeScript assist into VS with a full JavaScript Language Service primarily based on TS. It supplies a TypeScript NuGet Package deal so you possibly can construct your entire app with MSBuild and VS will do the correct factor.
NEW: Beginning in Visible Studio 2022, there’s a new JavaScript/TypeScript mission kind (.esproj) that permits you to create standalone Angular, React, and Vue initiatives in Visible Studio.
The .esproj idea is nice for people acquainted with Visible Studio as we all know {that a} Resolution accommodates a number of Tasks. Visible Studio manages recordsdata for a single software in a Challenge. The mission consists of supply code, sources, and configuration recordsdata. On this case we will have a .csproj for a backend Internet API and an .esproj that makes use of a shopper aspect template like Angular, React, or Vue.
Factor is, traditionally when Visible Studio supported Angular, React, or Vue, it is templates had been outdated and never up to date sufficient. VS2022 makes use of the native CLIs for these entrance ends, fixing that downside with Angular CLI, Create React App, and Vue CLI.
If I’m in VS and go “File New Challenge” there are Standalone templates that resolve Instance 2 above. I am going to decide JavaScript React.
Then I am going to click on “Add integration for Empty ASP.NET Internet API. This can give me a frontend with javascript able to name a ASP.NET Internet API backend. I am going to follow along here.
It then makes use of the React CLI to make the entrance finish, which once more, is cool because it’s no matter model I would like it to be.
Then I am going to add my ASP.NET Internet API backend to the identical answer, so now I’ve an esproj and a csproj like this
Now I’ve a pleasant clear two mission system – on this case extra JavaScript centered than .NET centered. This one makes use of npm to startup the mission utilizing their net improvement server and proxyMiddleware to proxy localhost:3000 calls over to the ASP.NET Internet API mission.
Here’s a React app served by npm calling over to the Climate service served from Kestrel on ASP.NET.
That is inverted than most ASP.NET People are used to, and that is OK. This reveals me that Visible Studio 2022 can assist both improvement model, use the CLI that’s put in for no matter Frontend Framework, and permit me to decide on what net server and net browser (by way of Launch.json) I would like.
If you wish to flip it, and put ASP.NET Core as the primary and then bring in some TypeScript/JavaScript, follow this tutorial because that is additionally attainable!
Sponsor: Make login Auth0’s downside. Not yours. Present the handy login options your clients need, like social login, multi-factor authentication, single sign-on, passwordless, and extra. Get started for free.
About Scott
Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, guide, father, diabetic, and Microsoft worker. He’s a failed stand-up comedian, a cornrower, and a e book creator.