Visual Studio cannot find afxres.h when it compiles the .rc file
Fix it fast
Most common cause, 1 of 3The 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.
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\setup.exe" modify ^
--installPath "C:\Program Files\Microsoft Visual Studio\2022\Community" ^
--add Microsoft.VisualStudio.Component.VC.ATLMFCShort 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.
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.
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find VC\Tools\MSVC\**\afxres.hThen find the line you see in this list and open its fix:
- 1The MFC component was never installed
vswhere prints nothing, and the project or its .rc file was created with MFC, often in an older Visual Studio - 2The project does not use MFC, but its .rc file still includes afxres.h
No source file includes afxwin.h or another afx header, and only the .rc file mentions afxres.h - 3MFC is installed for a different toolset or CPU
vswhere 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.
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -requires Microsoft.VisualStudio.Component.VC.ATLMFCFix
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.
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\setup.exe" modify ^
--installPath "C:\Program Files\Microsoft Visual Studio\2022\Community" ^
--add Microsoft.VisualStudio.Component.VC.ATLMFCVerify
The vswhere -find command now prints a path to afxres.h, and a rebuild gets past the resource compile step.
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -find VC\Tools\MSVC\**\afxres.hConfirmed by learn.microsoft.com
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.
findstr /s /i /n "afxres.h afxwin.h" *.rc *.h *.cppFix
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.
// 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.
msbuild MyApp.vcxproj -t:RebuildConfirmed by learn.microsoft.com
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.
findstr /i "PlatformToolset" MyApp.vcxprojFix
Add the MFC component that matches the project's toolset and platform, or retarget the project to the latest toolset that already has MFC.
:: 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.MFCVerify
Every configuration and platform in the solution builds, including ARM64 or the v142 projects.
msbuild MyApp.sln -t:Rebuild -p:Platform=ARM64Confirmed by learn.microsoft.com
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.