Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Node.js, PHP and APIs

Visual Studio cannot find afxres.h when it compiles the .rc file

Your error

fatal error RC1015: cannot open include file 'afxres.h'.1 more line it can show

Fix it fast

Most common cause, 1 of 3

The MFC component was never installed

Open the Visual Studio Installer, choose Modify, and under Desktop development with C++ tick the MFC entry for the latest build tools.

Fix
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\setup.exe" modify ^
  --installPath "C:\Program Files\Microsoft Visual Studio\2022\Community" ^
  --add Microsoft.VisualStudio.Component.VC.ATLMFC
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

RC1015: cannot open include file 'afxres.h' means the resource compiler cannot find the MFC header. In Visual Studio 2022 and 2026, MFC is an optional part of Desktop development with C++, so install component Microsoft.VisualStudio.Component.VC.ATLMFC, or the MFC component for your toolset and CPU. A project that never uses MFC can include winres.h instead.

  • Applies to Visual Studio 2022 17.14 (v143 toolset), Visual Studio 2026 18.0 (Latest MSVC), Visual Studio Installer and vswhere
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Ask vswhere, which ships with the Visual Studio Installer, to look for afxres.h inside the newest Visual Studio instance. No output means MFC is not installed at all; a hit under a different MSVC version or CPU folder than your project uses points to cause 3.

Run this first
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find VC\Tools\MSVC\**\afxres.h

Then find the line you see in this list and open its fix:

  1. 1The MFC component was never installedvswhere prints nothing, and the project or its .rc file was created with MFC, often in an older Visual Studio
  2. 2The project does not use MFC, but its .rc file still includes afxres.hNo source file includes afxwin.h or another afx header, and only the .rc file mentions afxres.h
  3. 3MFC is installed for a different toolset or CPUvswhere finds afxres.h, but only under the latest MSVC folder, while the project targets the v142 toolset or the ARM64 platform

What does the error look like?

  • fatal error RC1015: cannot open include file 'afxres.h'.
  • Resource Compiler Fatal Error RC1015

Cause 1 of 3

The MFC component was never installed

You seevswhere prints nothing, and the project or its .rc file was created with MFC, often in an older Visual Studio

Check

RC1015 for afxres.h follows from how Visual Studio is installed: since Visual Studio 2017, MFC and ATL are optional sub-components of the Desktop development with C++ workload. A default install of that workload leaves them out, so afxres.h is not on disk.

Check
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -requires Microsoft.VisualStudio.Component.VC.ATLMFC

Fix

Open the Visual Studio Installer, choose Modify, and under Desktop development with C++ tick the MFC entry for the latest build tools. From a command prompt, the installer accepts the same component ID with --add; --installPath is required for modify.

Fix
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\setup.exe" modify ^
  --installPath "C:\Program Files\Microsoft Visual Studio\2022\Community" ^
  --add Microsoft.VisualStudio.Component.VC.ATLMFC

Verify

The vswhere -find command now prints a path to afxres.h, and a rebuild gets past the resource compile step.

Verify
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find VC\Tools\MSVC\**\afxres.h

Confirmed by learn.microsoft.com

Did this fix it?

Cause 2 of 3

The project does not use MFC, but its .rc file still includes afxres.h

You seeNo source file includes afxwin.h or another afx header, and only the .rc file mentions afxres.h

Check

Microsoft's technical note TN035 explains that AFXRES.H holds the framework's standard symbols and itself includes WINRES.H, the part of WINDOWS.H that generated .RC files need. A plain Win32 project that only copied the line from an old template gains nothing from MFC.

Check
findstr /s /i /n "afxres.h afxwin.h" *.rc *.h *.cpp

Fix

Replace the include in the .rc file, and in its TEXTINCLUDE block if present, so the resource editor does not write it back. Keep afxres.h only if the resources use MFC symbols such as ID_FILE_NEW.

Fix
// MyApp.rc, before
#include "afxres.h"
// after
#include "winres.h"

Verify

The project builds without the MFC component, and the resource editor still opens the .rc file.

Verify
msbuild MyApp.vcxproj -t:Rebuild

Confirmed by learn.microsoft.com

Did this fix it?

Cause 3 of 3

MFC is installed for a different toolset or CPU

You seevswhere finds afxres.h, but only under the latest MSVC folder, while the project targets the v142 toolset or the ARM64 platform

Check

The Visual Studio component directory lists MFC as separate components per toolset and architecture. The x86 and x64 component for the latest tools does not cover ARM64, and the v142 build tools carry their own MFC component, so a project pinned to one of those still cannot open the header.

Check
findstr /i "PlatformToolset" MyApp.vcxproj

Fix

Add the MFC component that matches the project's toolset and platform, or retarget the project to the latest toolset that already has MFC.

Fix
:: ARM64 builds with the latest tools
--add Microsoft.VisualStudio.Component.VC.MFC.ARM64
:: projects that stay on the v142 toolset
--add Microsoft.VisualStudio.Component.VC.14.29.16.11.MFC

Verify

Every configuration and platform in the solution builds, including ARM64 or the v142 projects.

Verify
msbuild MyApp.sln -t:Rebuild -p:Platform=ARM64

Confirmed by learn.microsoft.com

Did this fix it?

How do I stop it coming back?

  • Export the installer configuration (.vsconfig) with the MFC components into the repository, so every developer and build agent installs the same parts.
  • Install build agents from the command line with explicit --add component IDs instead of the default workload selection.
  • For new Win32 projects that do not use MFC, start resource files from winres.h so the dependency never appears.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.