Target "build" does not exist in the project for Visual Studio
Asked Answered
H

7

68

I'm checking out code for a project where contributors use different dev tools for coding in C sharp (C#). My .csproj file was manipulated by someone using Sharp develop and now I get 'The target "build" does not exist in the project'.

  • How can I correct this?

I am using Visual Studio 2008 SP 1.

Harlequinade answered 9/1, 2010 at 23:42 Comment(0)
Q
-10

If you were to do it manually, I would take all the files and add them back to a new project file one by one.

Quatrain answered 10/1, 2010 at 0:5 Comment(2)
Yep, I should have thought of that first.Harlequinade
I tried this and it still gave me the same build error.Ress
S
177

The accepted answer is a workaround, not a solution. You need to open the .csproj file for editing in a text editor and ensure the following line is present in there

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

If not add it to the end.

Note: For VS2008, this may be $(MSBuildToolsPath)

Shopper answered 11/3, 2010 at 1:32 Comment(4)
In case of SharePoint 2007 project that uses the stsdev.exe utility adding <Import Project="DeploymentFiles\Microsoft.SharePoint.targets" /> in the .csproj file may help.Autocrat
I was having the same issue but on a Xamarin.Android project. The import that works for this kind of issue is <Import Project="$(MSBuildExtensionsPath)\Xamarin\Android\Xamarin.Android.CSharp.targets" />.Birr
Given how often one has to edit the .csproj you'd think Visual Studio would provide a right-click option to do it.Mispronounce
What to do for a F# project I'm trying to build with MS VS 2019 Build Tools ?Pergolesi
D
6

Just had this issue with Visual Studio 2017 v15.9.2 and wiping out the .vs folder in the solution root was the only solution that worked for me.

Danialah answered 22/2, 2019 at 11:5 Comment(1)
I just had this when transferring an ASP.NET MVC 5 project from my older personal development machine to a new one I just bought, using Visual Studio 2019 16.9.4 on the new machine, and VS 16.9.3 on the old machine. Thanks for the tip!Lashawnda
A
5

I had the same problem when I upgraded a project built in VS2005 to VS2010 Express. Initially the VS2010 refused to load the project with error message "Project is not supported by this installation". After trying many solutions finally it worked and my guess is it worked when two lines were removed from the project file that related to build target. However it presented a new problem that the project would not build. Of course this makes sense as I removed the entries from project file that told Visual Studio how to build the project.

Finally got hold of another project that was working on VS2010 Express and copied following lines to the project that was failing. It worked after that.

 <Import Project="$(MSBuildBinPath)\Microsoft.VisualBasic.targets" />
 <Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v10.0\WebApplications\Microsoft.WebApplication.targets" />

Hope this helps someone.

Amphibole answered 26/1, 2011 at 13:59 Comment(0)
S
5

Deleting the .vs folder worked for me.

Sena answered 24/6, 2019 at 7:47 Comment(0)
I
3

As for me, I was trying to build a solution with F# projects (.fsproj files).

The problem was that I was using an old MSBuild (located in path %WINDIR%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe).

When I tried to run the new version, located in "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe", everything started working fine.

Or in case you're using Visual Studio Enterprise, or GithubActions CI, then the path is "%ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe".

I found them by running this:

"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -find MSBuild\**\Bin\MSBuild.exe
Impress answered 30/8, 2019 at 7:4 Comment(0)
F
0

Another possibility for this error to occur is incorrect path for an imported project. In my case it was a .wixproj file, where I imported WIX using this line:

<Import Project="$(ProjectDir)..\..\packages\WiX.3.14.1\build\wix.props"
        Condition="Exists('$(ProjectDir)..\..\packages\WiX.3.14.1\build\wix.props')" />

The path was incorrect, but due to Condition there were no complaints. But without that Import there is no Build target defined.

PS For those wondering why there is a condition on the import - to allow nuget restore command to go smoothly.

Frodi answered 10/7, 2024 at 7:54 Comment(0)
Q
-10

If you were to do it manually, I would take all the files and add them back to a new project file one by one.

Quatrain answered 10/1, 2010 at 0:5 Comment(2)
Yep, I should have thought of that first.Harlequinade
I tried this and it still gave me the same build error.Ress

© 2022 - 2025 — McMap. All rights reserved.