Visual Studio 13(C#)项目数据库迁移后构建挂起求助
Hey there! Sorry to hear you're stuck with this frustrating build freeze in Visual Studio 2013 after your database server migration. Let's walk through the most common fixes for this issue, starting with the most likely culprits:
1. Verify Your Database Connection Strings
Since your database moved to a new server, outdated connection strings are the top suspect here. VS might be hanging while trying to connect to the old (now unreachable) server during build:
- Open your project's
App.configorWeb.configfile - Locate the
<connectionStrings>section - Double-check that all connection strings point to the new database server's address, not the old one
- Also, confirm if any pre-build scripts or startup code (like EF model initialization) is trying to connect to the old server—comment those out temporarily to test
2. Disable Database-Related Auto-Actions During Build
Visual Studio sometimes runs background database tasks during builds that can hang if the server is unreachable:
- If you're using Entity Framework with an EDMX model:
- Right-click the EDMX file → Properties
- Change the Build Action to
None - Try rebuilding the solution to see if the freeze stops
- Check pre/post build events:
- Right-click your project → Properties → Build Events
- Look for any commands that interact with the database (like
sqlcmdscripts) - Comment out these events temporarily with
::at the start of each line and test the build
3. Clean Up VS Caches and Project Files
Corrupted cache files often cause odd build issues, especially after configuration changes:
- Force-close VS using Task Manager (end the
devenv.exeprocess if it's unresponsive) - Delete your project's
binandobjfolders (these hold build artifacts that might reference the old server) - Clear VS's component cache:
- Navigate to
%LOCALAPPDATA%\Microsoft\VisualStudio\12.0(12.0 is the version number for VS2013) - Delete all files in the
ComponentModelCachefolder
- Navigate to
- Clear NuGet cache (if you use NuGet packages):
- Open VS → Tools → Options → NuGet Package Manager → General
- Click Clear All NuGet Caches
4. Launch VS in Safe Mode
Third-party extensions can interfere with the build process. Test if the freeze happens in safe mode:
- Hold down the Ctrl key while launching Visual Studio 2013
- Select Safe Mode when prompted
- Try building your solution in this mode—if it works, you'll need to disable extensions one by one to find the culprit
5. Enable Detailed Build Logs
If the above steps don't work, get more info about where the build is hanging:
- Open VS → Tools → Options → Projects and Solutions → Build and Run
- Set MSBuild project build output verbosity to Detailed or Diagnostic
- Attempt to build again (even if it freezes)
- Force-close VS, then check the Output window logs—look for the last task that ran before the freeze, this will point you to the exact step causing the issue
6. Repair Visual Studio 2013
As a last resort, repair your VS installation to fix any corrupted system files:
- Open Control Panel → Programs and Features
- Find Microsoft Visual Studio 2013 in the list
- Right-click it → Change → Repair
- Wait for the repair process to complete, then restart VS and try building again
Give these steps a try in order—start with the connection string check, since that's the most obvious issue after a database migration. Hopefully one of these gets you back up and running!
内容的提问来源于stack exchange,提问作者Antonio

