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

Viewed 37273

I'm building/packing a web application in a build server, and it fails with the following message:

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

This is the build server environment:

  • Windows Server 2008 R2 Standard
  • TeamCity 8.0.4
  • .NET 4.5
  • Windows SDK for Windows 7 and .NET 4
  • Windows SDK for Windows 8 and .NET 4.5
  • Portable Class Library Tools
  • ASP MVC 4

It is a ASP MVC 4 web application, targeting .NET 4.5.

The build configuration consists in building the solution with MSBuild, and deploying it to a package, so I can publish it later.

Through the log of TeamCity, I can see the error arising when MSBuild runs aspnet_compiler.exe.

The builds with no problem in my DEV machine and can also publish it to a local IIS without problems.

Does anyone know what may be causing this issue?

UPDATE

See my answer below.

18 Answers

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\2 017\Professional\Common7\IDE\PublicAssemblies\CppCodeProvider.dll"

e.g.


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

Assembly successfully added to the cache

C:\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.

In my case I had added an angular website to my solution which caused this error.

Resolved the error with following steps.

On the menu bar, choose Build > Configuration Manager.

In the Project contexts table, exclude the angular website (which contained node_modules)

In the Build column for the project, clear the check box.

Choose the Close button, and then rebuild the solution.

In my case it was the node_modules folder. I made this change in my csproj file for my .net 4.8 app to fix it.

This will just add the hidden attribute to the node_modules folder and then unhide it after the Razor pages are compiled.

<Target Name="MvcBuildViews" AfterTargets="AfterBuild" Condition="'$(MvcBuildViews)'=='true'">
  <Exec Command="attrib +H &quot;$(ProjectDir)node_modules&quot;" />
  <AspNetCompiler VirtualPath="temp" PhysicalPath="$(WebProjectOutputDir)" />
  <Exec Command="attrib -H &quot;$(ProjectDir)node_modules&quot;" />
</Target>

My solution to this error was a combination of two pre-existing answers on this page. I had a .h file in my web project directory that had not caused a problem until I tried to build the project on a VS 2017 machine.

In my case I simply zipped it up, but the upshot seems to be that you can no longer keep unrelated code files in the web directory or VS will trip up trying to compile them.

I solved it with deleting node modules folder then running npm i from git bash and not from VS2019 built in terminal.

Copy cppprovider.dll from Visual Studio 2015 installation path to:

C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies

An easy way to solve is that to reference the CppCodeProvider.dll. It may locate at

C:\Program Files (x86)\Microsoft Visual Studio{version}\{edition}\Common7\IDE\PublicAssemblies

For example:

C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\PublicAssemblies\CppCodeProvider.dll

It will be in the bin folder.

enter image description here

I moved my solution from VS2019 to VS2022 and was having this error when I tried to publish solution. This is how I made the error disappear.

  • Right-click on References>> Add References
  • Then Search for Microsoft.VisualC
  • tick Microsoft.VisualC and Microsoft.VisualC.VSCodeProvider
  • click ok. Error gone!

I installed VS2019 on a new laptop but kept getting the same error message as the OP. (it still worked fine on my desktop PC).

After a day or so of trying every answer on here and Google, and getting no joy, I tried using, from the toolbar, Build -> Publish Web App, which built my website into the Publish folder ok.

I then took this 'Publish' folder and copied it to a new place on my C:drive.

Then after closings and re-opening VS2019, started with "continue without code".

Then File -> Open -> Web Site... select my 'Publish' folder, and hooray I can now build and debug my project locally.

Related