question

YuLan-9133 avatar image
0 Votes"
YuLan-9133 asked RajivKumar-6027 answered

Msbuild reports MSB3021 from time to time

I have a larget project and when I run msbuild, it reports below errors from time to time, like 5 out of 10 times it reports errors.
When it fails, I have to msbuild multiple times to get it built successfully.

I feel like it is due to some kind of parellal building which causing issues that when a project tries to access dll A, dll A might still be building so it reports the dll is locked by msbuild.exe.

Any idea?

Could not copy "D:\repo\MyRepo\target\dev\MyDir\debug\amd64\myTest.dll" to "d:\repo\MyRepo\Target\Distrib\MyDirOther\all\debug\amd64\myTest.dll". Exceeded retry count of 10. Failed. The file is locked by: "System (4), MSBuild.exe (11396), MSBuild.exe (11296)"
error MSB3021: Unable to copy file "D:\repo\MyRepo\target\dev\MyDir\debug\amd64\myTest.dll" to "d:\repo\MyRepo\Target\Distrib\MyDirOther\all\debug\amd64\myTest.dll". The process cannot access the file 'd:\repo\MyRepo\Target\Distrib\MyDirOther\all\debug\amd64\myTest.dll' because it is being used by another process.

vs-msbuild
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

AnnaXiu-MSFT avatar image
0 Votes"
AnnaXiu-MSFT answered KhanifHanafi-1742 published

Hi @YuLan-9133 ,

Welcome to Microsoft Q&A!

Please try the following steps:
1. Close all instances of Visual Studio
2. Delete the hidden .vs, bin and obj folders in the project folder
3. Relaunch your Visual Studio
4. Clean the solution and rebuild your project

Sincerely,
Anna


If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.



· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Same.
The build succeeds but after then it starts to fail randomly again.

0 Votes 0 ·

Which version of Visual Studio are you using? Have you tried to create a new project and check if the error occurs in specific project or not?

0 Votes 0 ·

i have same issue too, after following step above or create new project. i still get that error (MSB3021 & MSB3027)

0 Votes 0 ·
RajivKumar-6027 avatar image
0 Votes"
RajivKumar-6027 answered

Tried following and works for me:

  1. close VS code

  2. delete bin and obj folder in solution (for all projects)

  3. dotnet run --configuration Release (we need to run in Release not debug)
    Its works
    try above steps and let me know
    thanks
    Rajiv Kumar
    rjkchaurasia@gmail.com


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.