Visual Studio 2017升级后测试数据项目报‘Build目标不存在’错误求助
Hey there, let's work through this issue together—since you're a junior dev, I'll break this down into simple, actionable steps that target the most common causes for this error:
1. Update SQL Server Data Tools (SSDT) in VS2017
This is the #1 fix for version mismatch issues when upgrading database-related projects:
- Open Visual Studio 2017
- Go to Tools > Extensions and Updates
- Switch to the Updates tab, then look for SQL Server Data Tools
- Install any available updates, then restart VS2017 completely
- Try building your test data project again after restarting
2. Verify & Fix the Project File (.sqlproj)
Sometimes the upgrade process doesn't properly update the project file's build targets. Here's how to fix it:
- Right-click your test data project in Solution Explorer → Unload Project
- Right-click the unloaded project → Edit [YourProjectName].sqlproj
- Look for lines like this (they import the required build targets for SSDT projects):
<Import Project="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets" Condition="Exists('$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\SSDT\Microsoft.Data.Tools.Schema.SqlTasks.targets')" />- If this line is missing, add it inside the
<Project>tag (you can copy this line from your working database project's .sqlproj file) - Also check that there are no typos or incorrect paths in existing Import tags
- If this line is missing, add it inside the
- Save the file, then right-click the project → Reload Project
- Attempt to build again
3. Migrate to a New VS2017-Compatible Project
If the above steps don't work, the original test data project might be using a deprecated template that VS2017 no longer supports:
- Create a new project in VS2017: Go to File > New > Project, search for SQL Server Project (or SQL Server Unit Test Project if you're using tests)
- Copy all your test data scripts, configurations, and files from the old project into this new one
- Set up any necessary references or deployment settings to match your original project
- Build the new project—this should use the correct build targets for VS2017
4. Check for Deprecated Project Types
If your test data project was a specialized type (like an old SSDT "Data Generation" project), VS2017 might have phased out support for it. In this case:
- Consider switching to a simpler approach: use a regular SQL project to store your test data scripts, then run them manually or via a post-deployment script
- Or use a testing framework like xUnit or NUnit with
SqlClientto insert test data programmatically—this is more flexible and supported across VS versions
Give these steps a try in order—start with updating SSDT, since that's the quickest fix for most upgrade-related build issues. If you hit a snag on any step, feel free to share more details about your test data project's type and what you see when editing the project file!
内容的提问来源于stack exchange,提问作者Lenster

