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

7

30

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?

Exploration answered 15/11, 2013 at 16:58 Comment(3)
A temporary solution is to copy the missing SqlServer.targets from a machine which has not yet upgraded to Visual Studio 2013 and placing it in the $(MSBuildToolsPath) directory (`C:\Program Files (x86)\MSBuild\12.0\bin` in my case). Is there a better solution than this?Exploration
I had the exact same problem. Explicitly installing the Microsoft Build Tools Package (standalone installer, separate from VS 2013) did not resolve the issue. I did have the file in the .NET Framework folder that you cited above and copying it to the new location worked as expected. Not sure why it was missing for you.Oliveira
I have a database project created directly in VS 2013, but there is no SqlServer.targets. Instead, there is <Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" />. Could manually updating targets fix your problem?Aphasia
L
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.

Luncheon answered 14/8, 2014 at 9:44 Comment(1)
And how did you upgrade the solution file to VS 2013?Mingmingche
M
31

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.

Mercerize answered 29/11, 2014 at 12:38 Comment(5)
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'Latex
As a side note, I had this problem when upgrading from Windows 7 to 10 (although still using VS2012) and this fix workedCady
This path worked for VS 2015 C:\Program Files (x86)\MSBuild\14.0\BinWiltz
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\BinKnickerbockers
Upgrading to VS 2022, you have to use C:\Program Files\Microsoft Visual Studio\2022\Professional\MSBuild\Current\Bin\amd64 to copy SqlServer.targets toIf
A
6

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!

Antaeus answered 2/3, 2015 at 15:48 Comment(2)
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.Boll
This solved it for me (along with copying SqlServer.targets to the right spot)Midiron
W
3

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.

Wonderstricken answered 1/11, 2017 at 20:6 Comment(0)
M
2

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\".

Mentally answered 2/11, 2018 at 20:55 Comment(0)
L
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.

Luncheon answered 14/8, 2014 at 9:44 Comment(1)
And how did you upgrade the solution file to VS 2013?Mingmingche
S
1

Solution 1:

If the project is a .csproj file, you should check if Visual Studio also generated a .sqlproj file while upgrading. If that is the case, you can add that to the solution instead.

Solution 2:

You can try to change the following line in the .sqlproj file:

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

to

<Import Project="$(MSBuildBinPath)\SqlServer.targets" />
Scalawag answered 16/5, 2016 at 12:5 Comment(0)
M
0

The Error Resulting from Several of these Solutions

I posted a specific question (C# VS 2013 Error 02019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', 'module', 'appcontainerexe' or 'winmdobj' CSC) regarding the fatal build error described by Chris Torng below Vladimir Dronov's answer:

Error 1 02019: Invalid target type for /target: must specify 'exe', 'winexe', 'library', 'module', 'appcontainerexe' or 'winmdobj' CSC


The Fix

I was able to get rid of the error related to SQL Server dev tool compatibility issues in VS2013 Community Edition by following the advice in this forum:

https://connect.microsoft.com/SQLServer/feedbackdetail/view/979839

Posted by bsclifton on 11/15/2014 at 7:18 AM

Had this issue too with the Community 2013 edition; Going to Tools->Extensions and Updates and updating "Microsoft SQL Server Update for database tooling" resolved the issue :)

If this doesn't work for you, I'd recommend checking out that forum as it offers up several other ideas for how to fix the problem

Malaspina answered 13/10, 2015 at 19:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.