none
Unable to remove directory because file 'db.lock' is being used by another process.

    Question

  • I just "upgraded" from Visual Studio Ultimate 2013 to Visual Studio Enterprise 2017.  I have 2 solutions that I use for automated testing.  Both solutions clean and build successfully in 2013, but only one will clean and build successfully in 2017.  The other solution generates the error Unable to remove directory 'C:\Source\...\...\...\.vs.' The process cannot access the file 'db.lock' because it is being used by another process.

    When I attempted to delete the db.lock file manually, it says the action cannot be completed because the file is open in ServiceHub.Host.CLR.x86.  

    I've looked at the on-line solutions, and the predominate choices are to uncheck Enable CodeLens, uncheck Enable full solution analysis, or add some if exist "$(TargetPath).locked" del "$(TargetPath).locked"... code into the Pre-Build Event block.  I've tried all of these, but none solved the issue.

    I noticed that in 2017, all 5 projects in the affected solution include Analyzers in the References.  None of the references in 2013 include Analyzers.  I've considered deleting these references, but the same situation applies to the solution that works, as well.  Since it's not a problem with one solution, why would it be a problem with the other solution?  

    If anyone has something else to try, I sure would appreciate suggestions.


    Kevin

    Wednesday, January 03, 2018 6:14 PM

Answers

  • Thanks, Jack.

    Tried those, too.  Didn't help.  Guess I'm going to have to bite the bullet and re-create the project.  'Preciate the help.


    Kevin

    • Marked as answer by KWD_AA Tuesday, February 06, 2018 2:40 PM
    Tuesday, February 06, 2018 2:40 PM

All replies

  • Hi,

    Welcome to MSDN forum.

    >>I just "upgraded" from Visual Studio Ultimate 2013 to Visual Studio Enterprise 2017.  I have 2 solutions that I use for automated testing

    What's the type of these project, WPF or something else?

    If you enable Lightweight Solution Load, please try to disable it from Tools->options->project and solutons.

    >>Unable to remove directory 'C:\Source\...\...\...\.vs.' The process cannot access the file 'db.lock' because it is being used by another process.

    Please have a look at the thread:

    Try to add the .vs folder in the .gitignore.

    You could use this one: https://github.com/github/gitignore/blob/master/VisualStudio.gitignore

    If you have any trouble adding the .gitignore, you could follow this article: https://elanderson.net/2016/09/add-git-ignore-to-existing-visual-studio-project/

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, January 04, 2018 8:30 AM
  • Hi Joyce.

    First, the projects in my solutions aren't WPF apps.  They're all .NET Framework 4.5.1 Class Libraries.

    I went through the links you provided, but we're not using GIT.  The only settings I have in Team Explorer are the Team Project and Team Project Collection options.

    Thanks for the input, though.  I appreciate it.

    One other thing I've noticed that's different between opening the project in 2013 and opening the project in 2017...  As I mentioned above, 2017 includes the Analyzers reference in each project, whereas 2013 does not.  Just out of curiosity, I right-clicked on it to see if I could remove the reference, but there is no option for removing it.  The only choices are Add Analyzer, Open Active Rule Set, or New Solution Explorer View.  When I opened the rule set, I can see the categories Managed Binary Analysis, Microsoft.CodeAnalysis.CSharp, etc... but there's also a message that says This is a Microsoft rule set and cannot be modified. Any changes will be saved to a copy of the file.  Since the "analysis" seems to be the problem, is there any way to shut it off besides the methods I've already tried (above)?


    Kevin

    Thursday, January 04, 2018 5:20 PM
  • Hi Kevin,

    Thank you for the update.

    Please close all instance of visual studio and go to the project location to delete or rename db.lock, then open the project in visual studio 2017 to build.

    Try to create a new project with the same project type in visual studio 2013 and build it in visual studio 2017 to check it if the issue persists. 

    >>One other thing I've noticed that's different between opening the project in 2013 and opening the project in 2017...  As I mentioned above, 2017 includes the Analyzers reference in each project,

    Analyzers are used to add custom error messages and warnings that appear live as you're typing, along with automatic code fixes to help you clean them up. It is one of the best and helpful key new features of Visual Studio 2015 and visual studio 2017.

    Best regards,

    Joyce


    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, January 05, 2018 9:40 AM
  • Hi Joyce.

    Closing VS 2017 allows me to delete the db.lock file, but as soon as I restart vs, the file gets locked again.  What I can do is go into Task Manager and end all of the ServiceHub.Host.CLR.x86 processes, which will allow me to rebuild the project.  I can then close down VS, re-open it and my test is displayed correctly in TestExplorer.  At this point, I can successfully execute the test.

    What bothers me the most is that my second project doesn't do this.  I can close out my problem project, open Project #2 (which is a duplicate project with additional page mapping thrown in), and it will rebuild just fine without having to go through the db.lock hassle.  For some reason, it's only on Project #1 that I have this issue.

    Can you think of any reason why similar projects act differently for the same VS app?


    Kevin

    Friday, February 02, 2018 9:39 PM
  • Hi Kevin,

    Please check that whether it is related to certain VS settings in your side.

    (1)Tools->Options: TextEditor->AllLanguages->CodeLens, uncheck Enable CodeLens

    (2)Please also turn off the Enable full solution analysis option.

    If possible, please reset your VS settings, view the result in your side.

    TOOLS->Import and Export Settings Wizard->Reset all settings->select “No, just reset settings, overwriting my current settings”->Choose a Default Collection of settings. Check it again.

    If still no help, since just the specific project has this issue, one idea is that you could create a blank solution, and add project files to the new blank solution, view the result, or just create a new project.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 06, 2018 2:40 AM
    Moderator
  • Thanks, Jack.

    Tried those, too.  Didn't help.  Guess I'm going to have to bite the bullet and re-create the project.  'Preciate the help.


    Kevin

    • Marked as answer by KWD_AA Tuesday, February 06, 2018 2:40 PM
    Tuesday, February 06, 2018 2:40 PM