Recently installed Visual Studio 2022, and have some old style mixed code aspx files with:
<%@ Page Language="C#" %>
<script runat="server"> ...
The c# code inside the script remains uncolorized. HTML code is colorized fine. These are just one-off aspx files to be edited and not necessarily part of a VS project.
This worked fine in VS2015.
Is there a setting to enable this in VS2022?
EDIT: Thanks all for responding, but perhaps I should have mentioned that these are really old style aspx files, as in for .NET 4.
I found this link:
https://learn.microsoft.com/en-us/dotnet/framework/install/guide-for-developers
Assume this is the reason for my issue. Although I don’t want to build any apps in VS, just view/edit individual aspx files and have the syntax highlighted.
Starting with Visual Studio 2022, Visual Studio no longer includes
.NET Framework components for .NET Framework 4.0 – 4.5.1 because these
versions are no longer supported. Visual Studio 2022 and later
versions can’t build apps that target .NET Framework 4.0 through .NET
Framework 4.5.1. To continue building these apps, you can use Visual
Studio 2019 or an earlier version.
2
Answers
I don't believe syntax highlighting for classic asp.net files with mixed code and html is possible in Visual Studio 2022.
There's a callout box in the middle this page that sort of addresses this matter, https://learn.microsoft.com/en-us/dotnet/framework/install/guide-for-developers
Just now I installed Visual Studio 2019, opened a classic asp.net file in it and got nice syntax highlighting and color coding.
Not the ideal solution, but it's what works. Leaving it here in case someone is struggling with this issue.
Try the following methods to ensure your C# code colorized correctly.
Method 1: Check File Association Settings
Open Visual Studio 2022.
Navigate to Tools -> Options.
In the left panel, select Text Editor -> File Extension.
In the File Extension field on the right, enter aspx.
In the Editor dropdown menu, select Web Forms Page Editor or HTML (Web Forms) Editor.
Click Add, then click OK.
Method 2: Check the Web development workload
Ensure that the Web development workload is enabled in Visual Studio Installer:
Open the Visual Studio Installer.
In the list of installed products, select Visual Studio 2022 and click Modify.
3.In the Workload TAB, make sure that the ASP.NET and Web development option is selected.
Method 3: Check Related Extensions
Navigate to Extensions -> Manage Extensions in Visual Studio.
Select Installed in the left panel.
Check for the following extensions: