如何在启动ASP.NET MVC项目或测试时跳过自动构建?
Hey there, I totally get how frustrating that 30-40 second delay is every time you fire up your app or run tests—especially when you haven’t touched a single line of code. Let’s walk through some tried-and-true fixes to cut out those unnecessary builds and get your workflow moving faster:
Configure Visual Studio to skip builds on run
Head to Tools > Options > Projects and Solutions > Build and Run. Here, tweak two key settings:- For your MVC app: Set On Run, when projects are out of date to Never build. This tells VS to skip building entirely if your binaries are already up to date.
- For tests: Open Test > Settings > Run Settings (or right-click in Test Explorer and select Settings) and enable Run tests without building first. This applies the same logic to your test suite.
Pro tip: You can still manually trigger a build anytime withCtrl+Shift+Bwhen you do make code changes.
Ditch unnecessary pre/post-build events
Right-click your MVC project, go to Properties > Build Events, and check the pre-build and post-build command lines. Sometimes scripts here run every time you launch the app—even if no code has changed. If any of these scripts aren’t essential (like copying files that don’t update often), comment them out or remove them to save time.Optimize incremental build settings
In your project’s properties, navigate to Build > Advanced. Make sure Incremental build is checked (it’s usually on by default, but double-check). Also, disable Rebuild project on run if build incrementally fails—this setting can force a full rebuild when it’s not actually needed.Use command line tools for instant launches
If you prefer working in the terminal, you can bypass the build step entirely with these commands:- Launch your MVC app:
dotnet run --no-build - Run your tests:
dotnet test --no-build
These commands use your last compiled binaries directly—perfect for when you know your code hasn’t changed.
- Launch your MVC app:
Check for extension-induced builds
If you use extensions like ReSharper or CodeRush, they might be triggering auto-builds behind the scenes. For ReSharper, go to Extensions > ReSharper > Options > Build, Execution, Deployment > Build and disable settings like Automatically build solution on save. Do the same for any other extensions that might be forcing builds on launch.
Try these steps one by one—start with the Visual Studio options since they’re the most straightforward. If you still run into delays, build events or extension interference are usually the culprit.
内容的提问来源于stack exchange,提问作者Andrew Vorobyov

