The referenced component could not be found

Problem

When I open a C# project in Visual Studio, none of the references are loading. In the error list it says “The referenced component could not be found” for several references.

Here’s a snippet showing just a few of the reference errors:

The referenced component ‘System’ could not be found.
The referenced component ‘Microsoft.CSharp’ could not be found.
The referenced component ‘System.Net.Http’ could not be found.
The referenced component ‘System.Data’ could not be found.
The referenced component ‘System.Core’ could not be found.

This usually means you need to restore the Nuget Package. In this case, it’s even showing this for .NET references.

Solution

I opened the .csproj file and saw an invalid imported project. This will be specific to your project, but for me the invalid imported project was NUnit3TestAdapter. To fix my problem, I had to manually remove references to this from the .csproj file.

To fix this problem:

  • Edit the .csproj file.
    • Try double-clicking the Project in Visual Studio. In newer versions, it’ll open the csproj file in the editor.
    • In older versions, right-click the project > click Open Folder in File Explorer > then edit the csproj with Notepad.
  • Find the invalid imported project.
  • Delete the invalid Import Project and Target sections.

Here’s an example:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
	<Import Project="packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props" Condition="Exists('packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" />
	<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
	<PropertyGroup>
	...
	</PropertyGroup>
	...
  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\NUnit3TestAdapter.3.9.0\build\net35\NUnit3TestAdapter.props'))" />
  </Target>
</Project>
Code language: HTML, XML (xml)

Note: This is a non-SDK style project file. It’s super long, so I’m only showing the relevant parts of it and surrounding sections for context.

Save the changes to make the referenced component warnings go away.

7 thoughts on “The referenced component could not be found”

    • 1. In Visual Studio right-click on your project
      2. Click Open Folder in File Explorer
      3. This will open the folder. In there, you’ll see the .csproj file
      4. Right-click on the .csproj file and Open With > Notepad (or Edit with Notepad++ if you have that installed)

      Reply
  1. I was dealing with this issue for hours. This was exactly the information I needed to fix the issue. Thanks so much!

    Reply

Leave a Reply to Joe Blevins Cancel reply