VS2019 Rebuild Solution MSBuild Cannot Delete .dll

Add-in Express™ Support Service
That's what is more important than anything else

VS2019 Rebuild Solution MSBuild Cannot Delete .dll
John Zabroski

Posts: 12
Joined: 2019-08-29
Is there an elegant fix to the following scenario?

1. Create Empty VS2019 Solution
2. Add RealTimeData sample project to the solution
3. Register the RealTimeData sample project with the UI using right-click in Solution Explorer on the RealTimeData project, go to Add In Express, select "Register project" in the context menu.
4. Rebuild solution

Expected behavior:
RE-build succeeds

Actual behavior:
RE-build fails with the following error:

Severity Code Description Project File Line Suppression State
Warning Unable to delete file "D:\source\trunk\Source\Ets.ExcelAddin.SubscriberRTDAddin\bin\Debug\SubscriberRTDAddin.dll". Access to the path 'D:\source\trunk\Source\Ets.ExcelAddin.SubscriberRTDAddin\bin\Debug\SubscriberRTDAddin.dll' is denied. SubscriberRTDAddin

Build Output:

------ Rebuild All started: Project: SubscriberRTDAddin, Configuration: Debug Any CPU ------
C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(5057,5): warning MSB3061: Unable to delete file "D:\source\trunk\Source\Ets.ExcelAddin.SubscriberRTDAddin\bin\Debug\SubscriberRTDAddin.dll". Access to the path 'D:\source\trunk\Source\Ets.ExcelAddin.SubscriberRTDAddin\bin\Debug\SubscriberRTDAddin.dll' is denied.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets(4366,5): warning MSB3026: Could not copy "D:\source\trunk\Source\Ets.ExcelAddin.SubscriberRTDAddin\bin\Debug\SubscriberRTDAddin.dll" to "bin\Debug\SubscriberRTDAddin.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'bin\Debug\SubscriberRTDAddin.dll' because it is being used by another process. The file is locked by: "MSBuild.exe (5648)"

After Un-registering the plugin, and re-building, the error goes away.
Posted 17 Sep, 2019 10:27:11 Top
Andrei Smolin

Add-in Express team

Posts: 17493
Joined: 2006-05-11
Hello John,

I've read somewhere that this issue occurs due to something in the way VS builds the project. I can't remeber details, though. Note that the issue is a warning, not error: should it fail to copy the file, it would do 10 tries and produced an error, not warning.

I've googled for

MSBuild warning MSB3026: Could not copy

and found https://stackoverflow.com/questions/18102859/visual-studio-could-not-copy-during-build

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 18 Sep, 2019 02:06:03 Top