Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running multiple parallel instances of a .NET Core App using dotnet run

Tags:

asp.net-core

I'm getting the following error:

C:\Program Files\dotnet\sdk\2.0.3\Microsoft.Common.CurrentVersion.targets(4052,5): warning MSB3026: Could not copy "obj\Debug\netcoreapp2.0\MyApp.dll" to "bin\Debug\netcoreapp2.0\MyApp.dll". Beginning retry 1 in 1000ms. The process cannot access the file 'C:\stackoverflow\MyApp\bin\Debug\netcoreapp2.0\MyApp.dll' because it is being used by another process. [C:\stackoverflow\MyApp\MyApp.csproj]

When trying to use dotnet run multiple times on the same project from different terminals. How do you easily run multiple instances of the same app while developing, without having to copy the folder?

If I start both at exactly the same time, it sometimes works :/

like image 571
Soren Avatar asked Jan 19 '18 10:01

Soren


3 Answers

I've used bat file to run 6 instances of app in one time. Only problem was when I started build of application and immediately run script. So I think you should make sure that build process ended. And then run you bat file with for example dotnet run repeated six times. Your app should be built to execute this file.

start /d "." dotnet run args
start /d "." dotnet run args
start /d "." dotnet run args
start /d "." dotnet run args
start /d "." dotnet run args
start /d "." dotnet run args
like image 190
MateuszWkDev Avatar answered Oct 19 '22 17:10

MateuszWkDev


I had the same problem and solved it using --no-build option:

dotnet run --no-build <path to .dll> <args>

Please take a look at: MSDN documentation

like image 14
Roman Koziolek Avatar answered Oct 19 '22 17:10

Roman Koziolek


The best thing in development time I've found is dotnet watch commandline tool.

You could have one bat file which will start multiple dotnet watch run <project> commands like in MateuszWkDev's answer.

Running in watch mode doesn't blocks files from editing and will rebuild and rerun applications once you'll edit your source files automatically.

Suppose you have bat file in src folder which has SomeProject, OtherProject and YetAnotherProject folders, which are contains csproj-files. Then bat file could looks like:

start /d "%~dp0\SomeProject"       dotnet watch run SomeProject
start /d "%~dp0\OtherProject"      dotnet watch run OtherProject
start /d "%~dp0\YetAnotherProject" dotnet watch run YetAnotherProject

Once you run this bat file, you'll got three terminals running dotnet watch run <project> commands.

like image 2
hal Avatar answered Oct 19 '22 18:10

hal