Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error the process cannot access the file because it is being used by another process while building project by CLI on .NET Core

Tags:

c#

.net

.net-core

I got following error while running dotnet build command on my .NET Core project.

C:\Program Files\dotnet\sdk\2.1.2\Microsoft.Common.CurrentVersion.targets(4106,5
 ): warning MSB3026: Could not copy "obj\Debug\netcoreapp2.0\Blog-Yantra.dll" to
 "bin\Debug\netcoreapp2.0\Blog-Yantra.dll". Beginning retry 1 in 1000ms. The proc
 ess cannot access the file 'E:\learn\blog\Blog-Yantra\bin\Debug\netcoreapp2.0\Bl
 og-Yantra.dll' because it is being used by another process.  [E:\learn\blog\Blog
 -Yantra\Blog-Yantra.csproj]

Screen shots of error message.

And my csproj file looks like:

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <TypeScriptToolsVersion>2.3</TypeScriptToolsVersion>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="2.0.1" />
    <PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="2.0.1" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.DotNet.Watcher.Tools" Version="2.0.0" />
  </ItemGroup>
</Project>
like image 676
Kiran Shahi Avatar asked Dec 26 '17 11:12

Kiran Shahi


2 Answers

Most likely an open .Net core process running and blocking, if on windows, just kill it through the task manager.

enter image description here

like image 51
Sgedda Avatar answered Oct 02 '22 17:10

Sgedda


The solution for me is to stop the IIS Express processes by right-clicking on the taskbar icon.

Or you can make a command line in "Pre-Build Event":

$(Solution)taskkill /FI "IMAGENAME eq iisexpress.exe" /F

Add this command in the "Properties" of your projet > "Build Events" Build Events

We don't have time to see if the command has been executed properly in "Ouput" view into "Build" section. Add this command line in "Pre-Build Event" to see the results:

cmd /c pause

You can remove this line after check...

like image 21
A. Morel Avatar answered Oct 02 '22 17:10

A. Morel