How to make web forms in VS 2022 (even though Microsoft recommends Blazor/.NET 6)
Last week, Microsoft confirmed that Web Forms, part of ASP.NET from the older .NET Framework, will not disappear in Visual Studio 2022, although it recommends Blazor as an alternative to .NET 6.
It’s not a deprecated deprecated technology, and it will continue to be supported – in other words, Web Forms is not Silverlight.
This news came in the Visual Studio 2022 17.2 announcement:
“In the initial release of Visual Studio 2022, we introduced a new feature for those who work with Web Forms applications and the designer. Web Live Preview allows your running application to be the design surface and provides code synchronization between the source and the web surface to help you navigate directly to the code file of the element you are editing.
After continuous developer studies with Web Forms applications, we have further improved the experiences in this release. We have also worked with several ASP.NET control providers to ensure their support in this new designer. If you are working in Web Forms, please switch to this feature using the Tools > Options > Web Forms Designer options menu and keep giving us your feedback!
In response to a comment questioning support for Web Forms, Microsoft said, “Web Forms is NOT deprecated, framework support is limited to critical updates, but all ASP.NET projects Full .NET Framework are fully supported. Although we are not investing in the Web Forms Framework, we still need to ensure that Web Forms developers can successfully develop their applications in Visual Studio.”
This ended issues like this January 29 question in the Microsoft documentation: “More support for Web Forms in Visual Studio 2022?”
The accepted answer to this question was: “Web Forms templates exist in Visual Studio 2022. Select ASP.NET Web Application (.NET Framework). A few clicks later, you can select Web Forms. If you don’t see the ASP.NET Web Application Option, then try installing the ASP.NET and Web Development Workflow using the Visual Studio installer.”
However, this might take a bit of explaining.
I had “ASP.NET and web development” installed as a workload as shown here
but I didn’t see the “ASP.NET and web development” option.
In the end, you need to perform a few more steps.
To access the option and enjoy the Web Live Preview feature mentioned above, you need to modify your VS 2022 program (I have v17.2 Community Edition) through the installer by clicking on the “Components” tab Individuals” next to “Workloads” and select “.NET Framework Project and Item Templates”, highlighted with a dotted box in this screenshot:
After downloading and installing, when creating a new project, I could “Search for templates” by typing “Web ASP.NET” in the search box (limiting the search to specifying C# as the language, Windows as platform and Web as the project type), whereupon the option “ASP.NET Web Application (.NET Framework)” has now appeared, described as “Project templates for creating ASP.NET applications. You can create ASP.NET Web Forms, MVC or Web API applications and add many other features in ASP.NET.”
Then by going to Tools > Options > Web Forms Designer as Microsoft mentioned above, you are presented with configurations for the designer,
including new Web Live Preview settings:
You will notice that Accessibility configuration is available. Microsoft has identified accessibility as a major stumbling block in the development team’s investigation into porting Web Forms to .NET 6, as explained in response to a comment in the release announcement post. v17.2 linked above: “Yes, there are A LOT of users still developing Web Forms Projects in Visual Studio. Let me explain more about why we are working on a new designer (“Web Live Preview”). Visual Studio, we have significant accessibility requirements that we must meet.The existing Web Forms designer is not accessible, and the code is written in such a way that it is almost impossible to make it accessible. also not up to date with the latest web technologies. We are creating a new designer to address these issues. Another goal of the new designer is to one day enable a similar experience for ASP.NET Core projects (no commitment yet there -low).”
Creating a new project results in this basic starter application:
As Microsoft stated above, the Web Forms Designer with Web Live Preview, shown below with the Split view (code and design) option, was actually introduced in July 2021 in VS 2022 Preview 2.
If “Legacy Web Forms designer” is chosen instead of “Web Live Preview” in the Tools > Options > Web Forms Designer configuration, the IDE looks slightly different in addition to acting differently, with options for Design views , Split, or Source (as shown in the graphic below), while Web Live Preview only has Design and Split View options.
Changing the source code is automatically reflected in the Design view. However, when debugging the project in a localhost IIS browser, changes made to the source code are not reflected in the design view or the running site, but the latter is updated by clicking the d button. browser link refresh, right next to the Hot Reload icon above the IDE.
Note, however, that the designer is relatively new and may be prone to issues, as I was presented with this message when launching the ASP.NET project with the legacy designer view (not using Web Live Preview): “Visual Studio has stopped responding for 11 seconds. Disabling Live Preview Web Extension 184.108.40.20637 may help.”
Microsoft recommends Blazor
Also, as mentioned, due to the difficulty of porting ASP.NET applications from .NET Framework to .NET 6 (successor to “.NET Core”), Microsoft recommends other options in the documentation titled “Migration Strategies ASP.NET web forms applications.”
“Direct migration from ASP.NET Web Forms to ASP.NET Core is not supported. However, there are strategies to make the transition to ASP.NET Core easier. You can migrate your Web Forms functionality to ASP.NET Core. NET Core successfully in:
- Keep non-web functionality away from your projects.
- Use of web APIs where possible.
- Considering Blazor as an option for a more modern UI.”
This page points to an ebook of the same name “for ASP.NET Web Forms developers looking for an introduction to Blazor related to their existing knowledge and skills. This book can help get a quick start on a new Blazor-based project or help chart a roadmap for modernizing an existing ASP.NET Web Forms application.”
This ebook contains passages including:
As of this writing, nearly half a million web developers use ASP.NET Web Forms every month. The ASP.NET Web Forms framework is stable to the point that documents, samples, books, and blog posts from a decade ago are still useful and relevant. For many .NET web developers, “ASP.NET” is still synonymous with “ASP.NET Web Forms”, as it was when .NET was first designed. Arguments about the pros and cons of ASP.NET web forms over other new .NET web frameworks can rage. ASP.NET Web Forms remain a popular framework for building web applications.
while reiterating the aforementioned message that Web Forms isn’t going away anytime soon:
Does this mean that ASP.NET Web Forms is dead and should no longer be used? Of course not! As long as the .NET Framework ships with Windows, ASP.NET Web Forms will be a supported framework. For many Web Forms developers, the lack of cross-platform and open source support is not an issue. If you don’t need cross-platform support, open source, or any of the other new features of .NET Core or .NET 6, you can stick with ASP.NET Web Forms on Windows. ASP.NET Web Forms will continue to be a productive way to write web applications for many years to come.
What was the purpose of this tip explaining how to do Web Forms projects in VS 2022.
It also responds to a Visual Studio Magazine reader who asked this question in the comments section of the recent “Microsoft: Web Forms Is No Silverlight” article: “Does the author therefore say that ASP.NET Web Forms will still be available in the . .. upcoming VS 2022 release schedule?”
The answer is yes.
David Ramel is an editor and writer for Converge360.