Troubleshoot MSBuild errors

2020/12/1 |

Symptoms

When you scan a .NET application in Lucent Sky AVM, the scan fails with one of the following errors:

MSBuild failed. ASP.NET compilation was skipped. (-42110062)

MSBuild failed. ASP.NET compilation failed. (-42110063)

Alternatively, the scan might complete but with one of the following warnings:

MSBuild failed. (41110021)

MSBuild failed. Some ASP.NET files were skipped during ASP.NET compilation. (41110062)

Cause

When scanning a .NET application, MSBuild is used to build the application. If errors occurred during MSBuild, the scan fails or completes partially.

Resolution

To resolve this issue, use the following methods starting with the first method below. If that does not resolve the issue, try the next method.

Method 1

Resolve errors in MSBuild logs, then scan the application again.

  • MSBuild logs contain one of the following error messages:

      Could not load file or assembly 'Microsoft.Build'
            
      Could not load type '...' from assembly 'Microsoft.Build.Framework'
    

    The MSBuild requested by the application is not available. If the application uses a version of MicrosofT Build Tools other than the ones bundled with .NET Framework, install the required or latest Microsoft Build Tools, such as Visual Studio Build Tools 2019, on the server running CLEAR Engine, and include MsBuild,latest in scan arguments.

  • MSBuild logs contain the following error message:

      error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v11.0\WebApplications\Microsoft.WebApplication.targets" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk.
    

    The application is developed with Visual Studio 2012 or an earlier version. Install the Visual Studio version used to develop the application on the server running CLEAR Engine.

  • MSBuild logs contain the following error message:

      error MSB4041: The default XML namespace of the project must be the MSBuild XML namespace.
    

    The application targets .NET Core, or otherwise uses a standalone version of Microsoft Build Tools such as Visual Studio Build Tools 2019. If the application targets .NET Core, install the required or latest Microsoft Build Tools, such as Visual Studio Build Tools 2019, on the server running CLEAR Engine, and include MsBuild,latest in scan arguments.

  • MSBuild logs contain the following error message:

      error CS0006: Metadata file 'C:\Windows\system32\config\systemprofile\.nuget\packages\...' could not be found.
    

    The application uses NuGet, and the source code archive does not include the required packages. Make sure the server running CLEAR Engine can access the NuGet feeds required by the application.

    Additionally, an issue in NuGet might prevent MSBuild from downloading the required packages. For more information on how to avoid this issue by configuring packages directories, view the following article in the Lucent Sky Knowledge Base:
    Administration guide to CLEAR Engine and Web UI § Configure packages directories

    Alternatively, copy the packages located in C:\Windows\SysWOW64\config\systemprofile\.nuget\packages to C:\Windows\System32\config\systemprofile\.nuget\packages.

  • MSBuild logs contain an error message indicating a syntax error, such as one of the following:

      error CS1002: ; expected.
            
      error CS1010: Newline in constant.
    
      error CS1525: Invalid expression term '}'
    

    There might be syntax or semantic errors in the source code, or the source code files might be using a different native (non-Unicode) encoding than the one used by the operating system. For more information on how to resolve encoding problems, view the following article in the Lucent Sky Knowledge Base:
    Troubleshoot encoding problems

  • MSBuild logs indicate that a property, such as SolutionDir, is null or undefined

    The project file might expect certain build properties to be set in the build process. To manually specify build properties, use the scan argument BuildProperties. Each property should be seperated by a comma instead of a semicolon. For example, BuildProperties,SolutionDir=..\..\Solutions,SkipPostBuildTask=1.

To learn more about common types of MSBuild errors, see the More Information section.

Method 2

Use direct binary analysis to scan .NET applications without building them in Lucent Sky AVM. To learn more about how to use direct binary analysis, view the following article in the Lucent Sky Knowledge Base:
Scan an application using direct binary analysis

Method 3

To disable binary analysis and only use source code analysis to scan a .NET application, include AnalysisEngines,20 in scan arguments.

More Information

Other common errors in MSBuild include:

  • An assembly reference is missing - MSBuild could not find the assembly of the namespace or class listed in the error message. This kind of error can typically be solved by either placing the required .dll in the bin directory of the project, or by installing the required runtimes on the server running CLEAR Engine.
  • A .targets file is not found - MSBuild could not find the .targets file listed in the error message. This can be solved by installing the necessary build tools or SDKs on the server running CLEAR Engine. Alternatively, locate the .targets file in the development environment, and place it in the same directory of the server running CLEAR Engine.
  • An external task failed - Some project files or .targets files include external tasks (such as executing an executable). If such task could not be executed by MSBuild, an error might occur. Most external tasks can be safely skipped by removing it from the project files or .targets files.
  • Syntax and semantic errors - There are two common causes of syntax and sematic errors in MSBuild, either that there are actual syntax and semantic errors in the source code, or the source code was compiled with an incorrect encoding. For more information on how to resolve encoding problems, view the following article in the Lucent Sky Knowledge Base:
    Troubleshoot encoding problems

If MSBuild failed due to compiler errors (such as CS1234 or BC1234, instead of MSB1234), see the following information:

  • For more information on C# compiler errors and resolutions view the following article on the Microsoft Learn website :
    C# Compiler Errors
  • For more information on Visual Basic compiler errors and resolutions, view the following article on the Microsoft Learn website:
    Error messages in Visual Basic