Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 734
Arthur Nunes Avatar asked Oct 12 '22 08:10

Arthur Nunes


2 Answers

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.

like image 84
Vanitas1440 Avatar answered Oct 19 '22 04:10

Vanitas1440


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.

like image 35
Arthur Nunes Avatar answered Oct 19 '22 05:10

Arthur Nunes