The Imported Project "C:\Microsoft.Csharp.Targets" Was Not Found

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

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" />

\MSBuild\16.0\Bin\Microsoft.CSharp.targets file not found

Please check the way it imports Microsoft.CSharp.targets in Kamban.csproj:

<LanguageTargets>$(MSBuildExtensionsPath)\$(VisualStudioVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>

According to the content of Kamban.csproj, it uses $(VisualStudioVersion) to locate Microsoft.CSharp.targets file.It works well for VS2017 and earlier versions, but not recommended in VS2019 since the location of msbuild has changed in VS2019.

See this document: Starting in VS2019 preview, MSBuild will use "Current" instead of the major version number as part of its path.
So the Microsoft.CSharp.targets file which you need for build process actually exists in path ...\2019\Community\MSBuild\Current\Bin\Microsoft.CSharp.targets instead of ...\2019\Community\MSBuild\16.0\Bin\Microsoft.CSharp.targets.

That's why it said file is missing in error message, cause it tried to find the targets file from wrong path.

As a Workaround:

Use the $(MSBuildToolsVersion) instead of $(VisualStudioVersion) to locate the .targets file.

Open and edit the Kamban.csproj file, change the value of LanguageTargets to:

<LanguageTargets>$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Bin\Microsoft.CSharp.targets</LanguageTargets>

Then the build engine can get correct path to find missing file.

(Note:This change works for both VS2017 and VS2019)

In addition:I've checked the open-source solution, it seems to target .net framework and .net standard, I'm not sure why this error message comes from SDK.targets, I suggest you rebuild the project in Visual Studio IDE or by msbuild command-line.

Microsoft.CSharp.Core.targets missing

I updated to TFS2018 and the problem got solved.

Is there a way to fix the imported project error for Microsoft.CSharp.targets, other than changing the reserved property to $(MSBuildBinPath)?

Errors you're receiving might indicate .NET framework installation issues.

Create simple MSBuild file which will show you if that's the case:

<?xml version="1.0" encoding="utf-8"?>

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="PrintInfo">
<Message Text="MSBuild tools path is:$(MSBuildToolsPath)" />

</Target>

</Project>



Related Topics



Leave a reply



Submit