Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet build is locking custom msbuild task dlls

See original GitHub issue


We are providing a tool that needs to be called before the build and after the tests which synchronize some analyzers (with their rulesets…) from a central server and at the end pushes some code quality information back to the server. To do so we are copying some targets and some tasks dlls inside a .sonarqube\bin folder.

We have had a couple of complaints from our users on the different channels (StackOverflow, GitHub Issues, our community forum) about the fact the dotnet build is locking some of our dlls.

When using only msbuild we don’t have such behavior but when using dotnet build or dotnet msbuild then the failure starts appearing.

For example see

We couldn’t find any easy way to prevent this behavior and before starting to try to hack around, we would prefer to have your input on what could be done.

Steps to reproduce

Example of commands:

dotnet tool install --global dotnet-sonarscanner
dotnet sonarscanner begin /k:"project-key"
dotnet build
dotnet sonarscanner end

Now if you do again the dotnet sonarscanner begin /k::project-key" you end up with the message Access to the path 'SonarScanner.MSBuild.Common.dll' is denied.

Known workarounds

  1. Kill dotnet process
  2. Use /nodereuse:false

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

livarcocccommented, Nov 27, 2018

Seems to me like this happens due to msbuild node re-use. we leave msbuild nodes alive with the intent of saving on startup time when doing consecutive builds.

You can turned it off by setting an environment variable: MSBUILDDISABLENODEREUSE=1 or you can run `dotnet build-server shutdown after the build.

livarcocccommented, Nov 30, 2018

Good to know if found out what is going on. No worries about the thread. Keep them coming.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom MSBuild task assembly locked on second build
When MSBuild loads and executes a custom MSBuild task the custom task assembly (and it's referenced assemblies) are locked.
Read more >
Visual Studio 2008 locks custom MSBuild Task assemblies
I'm developing a custom MSBuild task that builds an ORM layer, and using it in a project. I'm being hampered by Visual Studio's...
Read more >
Chasing an MSBuild task devenv.exe file lock
This file locking behavior has been quite odd and confusing, since MSBuild and VS teams have been making lots of changes to make...
Read more >
MSBuild custom task and assembly locks - mnaoumov.NET
MSBuild loads custom assembly dll into its main AppDomain and therefore this assembly becomes locked until MSBuild exited. So by default after ...
Read more >
Rider spawns its own MSBuild processes which locks files ...
So in your case it seems there are custom build tasks are integrated into build (and design-time build) process and locks some project...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found