Project fails to load due to missing SqlServer.targets file after upgrading to Visual Studio 2013

15,428

Solution 1

I had the same problem when trying to build a VS 2010 solution under VS 2013. The fix was to upgrade the solution file to VS 2013 first. After that it worked without further modifications.

Solution 2

Just copied SqlServer.targets from C:\Windows\Microsoft.NET\Framework\v3.5 to C:\Program Files (x86)\MSBuild\12.0\Bin and it helps. VS2013 is now able to open the old project.

Solution 3

I had a similar problem when upgrading from Visual Studio 2008 to 2013. It took awhile but I had to install the SSDT for VS 2013 (again), then I created a new database project to find out the relative path to the new sqlserver.targets file. It should be as follows:

  <Import Condition="'$(SQLDBExtensionsRefPath)' != ''" Project="$(SQLDBExtensionsRefPath)\Microsoft.Data.Tools.Schema.SqlTasks.targets" />
  <Import Condition="'$(SQLDBExtensionsRefPath)' == ''" Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />

The biggest hindrance that I found to fixing this error was trying to understand the error message provided (BC2014: the value 'database' is invalid for option 'target')

Hope this helps!

Solution 4

I had the same problem and I solved this way: Just create a file named 'SQLServer.targets' on 'C:\Windows\Microsoft.NET\Framework\v4.0.30319' with the following content:

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

    <PropertyGroup>
           <SqlClrTargetsFullPath>$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v10.0\TeamData\Microsoft.Data.Schema.SqlClr.targets</SqlClrTargetsFullPath>
    </PropertyGroup>

    <Import Project="$(SqlClrTargetsFullPath)" Condition="Exists('$(SqlClrTargetsFullPath)')"/>
</Project>

Good luck.

Solution 5

This can also occur when opening an older project in Windows 10

I had the same problem (SqlServer.targets was not found) when opening an old SQL Server CLR assembly in Visual Studio 2010 on Windows 10, the same version used originally to write the assembly.

Confirmed the same project opened perfectly fine in Visual Studio 2010 on a Windows 7 computer.

Solution

Pay attention to the error message. In my case it was:

The imported project “C:\Windows\Microsoft.NET\Framework\v4.0.30319\SqlServer.targets” was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

Simply copy SqlServer.targets from the location indicated in Vladimir Dronov's answer, "C:\Windows\Microsoft.NET\Framework\v3.5\SqlServer.targets", to the directory indicated in the error message.

In my case that was "C:\Windows\Microsoft.NET\Framework\v4.0.30319\".

Share:
15,428
Chris
Author by

Chris

A full-stack web application developer, working at Enable.

Updated on June 28, 2022

Comments

  • Chris
    Chris almost 2 years

    Having upgraded to Visual Studio 2013, I have found that an old SQL project fails to load when I attempt to open a solution. The error displayed is:

    The imported project "C:\Program Files (x86)\MSBuild\12.0\bin\SqlServer.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk. C:\Some\Path\To\Project\Database.sqlproj

    In my .sqlproj file I have the line

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

    which in Visual Studio 2012 resolves to C:\Windows\Microsoft.NET\Framework\v4.0.30319\SqlServer.targets but in Visual Studio 2013 this resolves to C:\Program Files (x86)\MSBuild\12.0\bin\SqlServer.targets. However, the SqlServer.targets file is in neither of these locations.

    Presumably this is due to MSBuild becoming part of Visual Studio, rather than it being part of the .Net Framework.

    Does anyone know how to fix this issue and to migrate this project to Visual Studio 2013?

  • CodeNaked
    CodeNaked over 9 years
    And how did you upgrade the solution file to VS 2013?
  • ChrisTorng
    ChrisTorng over 9 years
    It's able to open the old project, but fail to build with error: CS2019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', 'module', 'appcontainerexe' or 'winmdobj'
  • Pragmatic Coder
    Pragmatic Coder over 8 years
    After I moved the SqlServer.targets into C:\Program Files (x86)\MSBuild\12.0\Bin I was getting an error: CS2019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', 'module', 'appcontainerexe' or 'winmdobj'. However, I added the two lines above into the sqlproj file and I was able to build successfully.
  • Ben Sutton
    Ben Sutton almost 8 years
    As a side note, I had this problem when upgrading from Windows 7 to 10 (although still using VS2012) and this fix worked
  • kampsj
    kampsj almost 7 years
    This path worked for VS 2015 C:\Program Files (x86)\MSBuild\14.0\Bin
  • Trent
    Trent over 6 years
    This solved it for me (along with copying SqlServer.targets to the right spot)
  • Bpainter
    Bpainter about 4 years
    Upgrading from 2017 to 2019, I had to copy from C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin to C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin