Web Application Build Error: The CodeDom provider type Microsoft.VisualC.CppCodeProvider could not be located Web Application Build Error: The CodeDom provider type Microsoft.VisualC.CppCodeProvider could not be located asp.net asp.net

Web Application Build Error: The CodeDom provider type Microsoft.VisualC.CppCodeProvider could not be located


For me this error was popping up in VS2017 when building the web project. The fix was to make the node_modules directory hidden in File Explorer. Apparently this stops the ASP.NET compiler from scanning all these files and thus prevents the error.


This post gave me an important clue: apparently ASP.NET precompilation scans the project and output files and tries to compile every source file it finds in its way, despite its language (see here).

In the case, my web app depends on a project which includes some unmanaged dll along a ".h" file. These files are copied to the output directory ("Copy if newer") so I can pinvoke it at runtime.

It seems ASP.NET precompilation finds the ".h" and tries to compile it, even though there is no need of it. And, as I see it, it fails because my build server does not has the tools for the job (it looks like CppCodeProvider comes with the .NET 2.0 SDK).

When I changed the project not to copy those files to the output directory, the build ran fine. I also tested copying the files, but with "PrecompileBeforePublish" set to false in the publish profile, and it also worked.

Now I have some options, but I don't like any of them:

  • Disable "PrecompileBeforePublish". I believe the main disadvantage of that is the app users experience will be slower on the first site access.

  • Try to exclude files from the output folder and add them again after pre-compilation. That seems a lot of work for something I shouldn't be worrying in first place.

  • Try to tell "aspnet_compiler.exe" to exclude the offending files/folder when executing. I don't know how to do it using the publish profile, because I only have control over "PrecompileBeforePublish". Also, it seems "aspnet_compiler.exe" does not offer that option (here and here).

I think for now I'll disable "PrecompileBeforePublish", because it seems a fast path with few caveats. But I believe there should be a better way to handle it, excluding folders or file types from precompilation using the publish profile.


For the benefit of those who find this later on google...

Root Cause

As the error implies, the assembly "Microsoft.VisualC.CppCodeProvider" couldn't be found.

This was added to the Global Assembly Cache (GAC) as part of Visual Studio 2015 installation, but not Visual Studio 2017.

The Fix

The proper fix is to add the missing reference to the GAC.

Run the "Developer Command Prompt" as admin, and run the following

gacutil /i "path to CppCodeProvider.dll" or gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PublicAssemblies\CppCodeProvider.dll"

e.g.

C:\Windows\System32>gacutil /i "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\PublicAssemblies\CppCodeProvider.dll"Microsoft (R) .NET Global Assembly Cache Utility.  Version 4.0.30319.0Copyright (c) Microsoft Corporation.  All rights reserved.Assembly successfully added to the cacheC:\Windows\System32>

On next build the following error is no longer thrown.

ASPNETCOMPILER error ASPCONFIG: The CodeDom provider type "Microsoft.VisualC.CppCodeProvider, CppCodeProvider, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" could not be located.