C# – Error: *.csproj could not import “$(MSBuildBinPath)\Microsoft.CSharp.targets” on MonoDevelop

cmonodevelop

So, I have MonoDevelop v5.7 on Linux Mint 16.
I create new C# ConsoleProject with default code on it

using System;

namespace Lab1
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            Console.WriteLine ("Hello World!");
        }
    }
}

and try to build it F7.
After that I have the error: Error: /../../Lab1/Lab1/Lab1.csproj: /../../Lab1/Lab1/Lab1.csproj could not import "$(MSBuildBinPath)\Microsoft.CSharp.targets" (Lab1).
Does any one have any suggestions?

Best Answer

I know this is late, but in my case, Mono was targeting a version of .NET that wasn't installed. This is fixed by changing the target framework.


I found the issue by running xbuild on the sln file:

xbuild myProject.sln

I got something like:

warning : Could not find project file /usr/lib/mono/3.5/Microsoft.CSharp.targets, to import. Ignoring.

The warning indicates that the project defaulted to targeting .NET 3.5, but I guess that version wasn't installed. Let's find a version that IS installed by searching for that missing file:

find /usr/lib/mono -name "Microsoft.CSharp.targets"

On my machine, /usr/lib/mono/4.5/Microsoft.CSharp.targets was listed, but you may have a different .NET version. Ignore the xbuild and msbuild paths.

Wherever it exists for you, go to your project, click the settings button next to your project in the solution pane (the dropdown button with the gear image) and click "Options". Then under "Build" you'll see "General", click that and change your "Target framework" to the .NET version where the folder contains the Microsoft.CSharp.targets file. In my case, this is 4.5.

Hopefully this helps someone.

Related Topic