C# MSBuild Problems and Solutions

This section lists solutions for some known MSBuild problems.

Error MSB4019: The imported project 'XYZ' was not found

Please check how the path of the imported project file is defined in the .csproj file of the module. It is often defined conditionally based on the existence of variables as shown in the following excerpt (line-breaks have been inserted for better readability):

    <VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
    <VSToolsPath Condition="'$(VSToolsPath)' == ''">
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(VSToolsPath)\WebApplications\Microsoft.WebApplication.targets" 
    Condition="'$(VSToolsPath)' != ''" />

If in this case the property "VisualStudioVersion" is not present, then the default value "10.0" is used to create the value for "VSToolsPath". This in turn is used in this case for the import of "Microsoft.WebApplication.targets".

If Sonargraph determined an incorrect "VisualStudioVersion", please provide this as an additional property, e.g. "/p:VisualStudioVersion=14.0". User-defined properties will be appended and thus override properties defined prior by Sonargraph.

'XYZ' was unexpected at this time.

If there is no MSBuild error message but a rather cryptic message about "... was unexpected at this time.", then this indicates that the Visual Studio Command Prompt could not be started. This is likely due to quotation marks in the PATH environment variable. See Visual Studio 2010 command prompt not working for details.

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

This error usually indicates that the version of MSBuild that is used by Sonargraph is too old to process the Visual Studio project files. Check in the C# preferences that the Visual Studio Command Prompt and the MSBuild executable are pointing to sufficiently recent versions (see Section 4.9.1, “C# Build Executor Configuration”).

Error NETSDK1005: Assets file 'project.assets.json' doesn't have a target for 'XYZ'.

This error usually indicates that 'restore' needs to be executed. Add the additional option '/restore' to the System-level configuration.