Nerdbank.GitVersioning: nbgv prepare-release fails with LibGit2SharpException: could not rmdir
I created a test git repo to try out nbgv. I followed these instructions. After running nbgv install
I committed the two added files. After this I ran nbgv prepare-release
which died with an exception.
From the Developer PowerShell in Visual Studio:
PS C:\Users\hugh\Documents\GitHub\click-once-test\ClickOnceTest> dotnet tool install -g nbgv
You can invoke the tool using the following command: nbgv
Tool 'nbgv' (version '3.5.119') was successfully installed.
PS C:\Users\hugh\Documents\GitHub\click-once-test\ClickOnceTest> nbgv install
PS C:\Users\hugh\Documents\GitHub\click-once-test\ClickOnceTest> nbgv prepare-release
v1.0 branch now tracks v1.0 stabilization and release.
Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> LibGit2Sharp.LibGit2SharpException: could not rmdir 'C:/Users/hugh/Documents/GitHub/click-once-test/ClickOnceTest/': The process cannot access the file because it is being used by another process.
at LibGit2Sharp.Core.Ensure.HandleError(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 136
at LibGit2Sharp.Core.Ensure.ZeroResult(Int32 result) in /_/LibGit2Sharp/Core/Ensure.cs:line 173
at LibGit2Sharp.Core.Proxy.git_checkout_tree(RepositoryHandle repo, ObjectId treeId, GitCheckoutOpts& opts) in /_/LibGit2Sharp/Core/Proxy.cs:line 226
at LibGit2Sharp.Repository.CheckoutTree(Tree tree, IList`1 paths, IConvertableToGitCheckoutOpts opts) in /_/LibGit2Sharp/Repository.cs:line 956
at LibGit2Sharp.Repository.Checkout(Tree tree, IEnumerable`1 paths, CheckoutOptions options) in /_/LibGit2Sharp/Repository.cs:line 942
at LibGit2Sharp.Commands.Checkout(IRepository repository, Tree tree, CheckoutOptions checkoutOptions, String refLogHeadSpec) in /_/LibGit2Sharp/Commands/Checkout.cs:line 152
at LibGit2Sharp.Commands.Checkout(IRepository repository, Branch branch, CheckoutOptions options) in /_/LibGit2Sharp/Commands/Checkout.cs:line 95
at LibGit2Sharp.Commands.Checkout(IRepository repository, String committishOrBranchSpec, CheckoutOptions options) in /_/LibGit2Sharp/Commands/Checkout.cs:line 53
at LibGit2Sharp.Commands.Checkout(IRepository repository, String committishOrBranchSpec) in /_/LibGit2Sharp/Commands/Checkout.cs:line 20
at Nerdbank.GitVersioning.ReleaseManager.PrepareRelease(String projectDirectory, String releaseUnstableTag, Version nextVersion, Nullable`1 versionIncrement, ReleaseManagerOutputMode outputMode) in D:\a\1\s\src\NerdBank.GitVersioning\ReleaseManager.cs:line 309
at Nerdbank.GitVersioning.Tool.Program.OnPrepareReleaseCommand(String project, String nextVersion, String versionIncrement, String format, String tag) in D:\a\1\s\src\nbgv\Program.cs:line 716
--- End of inner exception stack trace ---
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Delegate.DynamicInvokeImpl(Object[] args)
at System.Delegate.DynamicInvoke(Object[] args)
at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()
There is a commit Set version to ‘1.0’ on my master branch, and version.json has been deleted from the working directory.
I am using Visual Studio 2022 17.4.3.
This also happens if I close Visual Studio and run nbgv
from a standalone Windows PowerShell console. Which suggests it’s not VS with an open handle to the ClickOnceTest dir (why is nbgv trying to remove that dir anyway?).
About this issue
- Original URL
- State: open
- Created a year ago
- Comments: 16
I was having the same issue, and I noticed that it specifically occurred when I ran
nbgv prepare-release
in a sub-directory; running it in the repository root seemed to complete without error. All of the cases reported here seem to be doing the same, either running it in the solution directory or in asrc
directory.Also relevant here is that the Visual Studio Developer PowerShell of course starts in the solution folder, meaning running it from there will fail by default, which probably adds to the confusion.