The imported project "C:\Microsoft.CSharp.targets" was not found

Viewed 169125

I got this error today when trying to open a Visual Studio 2008 project in Visual Studio 2005:

The imported project "C:\Microsoft.CSharp.targets" was not found.

19 Answers

Open your csproj file in notepad (or notepad++) Find the line:

<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

and change it to

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />

This is a global solution, not dependent on particular package or bin.

In my case, I removed Packages folder from my root directory.

Maybe it happens because of your packages are there but compiler is not finding it's reference. so remove older packages first and add new packages.

Steps to Add new packages

  • First remove, packages folder (it will be near by or one step up to your current project folder).
  • Then restart the project or solution.
  • Now, Rebuild solution file.
  • Project will get new references from nuGet package manager. And your issue will be resolved.

This is not proper solution, but I posted it here because I face same issue.

In my case, I wasn't even able to open my solution in visual studio and didn't get any help with other SO answers.

In my case I could not load one out of 5 projects in my solution.

It helped to close Visual Studio and I had to delete Microsoft.Net.Compilers.1.3.2 nuget folder under packages folder.

Afterwards, open your solution again and the project loaded as expected

Just to be sure, close all instances of VS before you delete the folder.

This link on MSDN also helps a lot to understand the reason why it doesn't work. $(MSBuildToolsPath) is the path to Microsoft.Build.Engine v3.5 (inserted automatically in a project file when you create in VS2008). If you try to build your project for .Net 2.0, be sure that you changed this path to $(MSBuildBinPath) which is the path to Microsoft.Build.Engine v2.0.

I deleted the obj folder and then the project loaded as expected.

I ran into this issue while executing an Ansible playbook so I want to add my 2 cents here. I noticed a warning message about missing Visual Studio 14. Visual Studio version 14 was released in 2015 and the solution to my problem was installing Visual Studio 2015 Professional on the host machine of my Azure DevOps agent.

After trying to restore, closing VS, deleting the failed package, reopening, trying to restore, multiple times I just deleted everything in packages and when I did a restore and it worked perfectly.

For me, the issue was the path.. When cloning the project that had a space in the name. The project folder was named "Sample%20-%205" instead of what it should be: "Sample - 5"

Opening the project was fine, but building failed with

Could not find the file: /packages/Microsoft.Net.Compilers.1.3.2/tools/Microsoft.CSharp.Core.targets

it seems now that the nuget packages folder has moved to a machine wide global cache, using VS2022

visual studio 2022 global nuget packages

For me the issue was that the solution was to deep into the documents folder and on windows 10 there is a path character limit which was reached. As soon as I moved the solution folder up couple of folders this fixed the issue.

Related