skip to Main Content

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.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    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.


  2. Try the following methods to ensure your C# code colorized correctly.

    Method 1: Check File Association Settings

    1. Open Visual Studio 2022.

    2. Navigate to Tools -> Options.

    3. In the left panel, select Text Editor -> File Extension.

    4. In the File Extension field on the right, enter aspx.

    5. In the Editor dropdown menu, select Web Forms Page Editor or HTML (Web Forms) Editor.

    6. Click Add, then click OK.

    Method 2: Check the Web development workload

    Ensure that the Web development workload is enabled in Visual Studio Installer:

    1. Open the Visual Studio Installer.

    2. 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.

    1. If this option is not installed correctly, click Modify to install the required components.

    Method 3: Check Related Extensions

    1. Navigate to Extensions -> Manage Extensions in Visual Studio.

    2. Select Installed in the left panel.

    3. Check for the following extensions:

    • ASP.NET and Web Tools or extensions of similar names.
    • Web Essentials or extensions of similar names.
    1. Try to install related extensions.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search