4

I am working on Asp.Net Mvc project with .Net Core 2.2. I can not run the last modified source code from command line/powershell. I tried manually calling dotnet clean and dotnet build before dotnet run but did not work. I can only run the last modified source code with cli if I run/debug my project within Visual Studio 2019 before.

How can i solve this problem?

I am using Windows 10. I have both SDK versions 3.1 and 2.2 installed but I declare the version by

<PropertyGroup>
  <TargetFramework>netcoreapp2.2</TargetFramework>
  ...
</PropertyGroup>

in my .csproj file and in the build path the target version is correct.

buraky
  • 937
  • 1
  • 11
  • 18
  • what errors do you get when running those cli commands ? – kord Apr 16 '20 at 17:29
  • @kord i don't get any error. But i can't see the reflection of changes i made on the code when i run. I am updating service codes, but their response is not changing when i run. However i get the expected results if i debug my project with Visual Studio – buraky Apr 16 '20 at 18:35

4 Answers4

4

TL;DR The problem was building the wrong project. Build the correct project or entire solution for certainty. dotnet build the main/entrance/single project does not trigger build for other dependency projects.

I am working on a solution which has many projects, and one of them is the application entrance which has the other projects as dependency. To run the application, you should dotnet run this project.

I thought building this entrance project would trigger build for dependency projects of the solution too. Turns out it does not.

The trick is, you can dotnet run only projects but you can dotnet build also solutions. So my fix was to build the solution.

buraky
  • 937
  • 1
  • 11
  • 18
  • My solution had multiple classlib projects and multiple consoleapp projects to test each lib. I had multiple configurations in the launch.json to pick which project was debugged, and assumed all the projects were rebuilt regardless which config I chose to run. That wasn't the case--I had to build the entire solution to force that. And adding "requireExactSource":false to the config would only address the symptom, not the problem. – Matthew Allen Aug 06 '20 at 20:31
  • Meant to say, I just edited the tasks.json file in the "build" node I changed the path to point to my sln rather than the csproj that was there. That built all of the projects automatically prior to debugging. – Matthew Allen Aug 06 '20 at 20:47
  • When I tried `dotnet run` on my `.sln` file, it ran the last built application. I only have one project in it, though. – Quirin F. Schroll Jul 04 '22 at 08:55
  • Just running `dotnet clean` allowed me to run `dotnet run` without the build step in my own project – HaulinOats Sep 14 '22 at 15:34
4

Had an alternate scenario cause this, for some reason I could not see code changes with dotnet build (from the project root) and dotnet run (from the project root). I could see the updated dates were not changing in the build folder even though it completes successfully. I could only get it to work as so:

dotnet clean
dotnet build
dotnet run

The key being clean empties out the build folder, maybe there is some permission issue or otherwise dotnet can't or doesn't detect it needs to update existing files.

edencorbin
  • 2,569
  • 5
  • 29
  • 44
  • Just running `dotnet clean` allowed me to finally get `dotnet run` to work (without the build step). Thank you. – HaulinOats Sep 14 '22 at 14:54
  • `dotnet clean` helped me get a better error message when I did `dotnet run` I was already running a `dotnet watch run` in another command line so it was preventing me from doing `dotnet run` – Cheon Nov 24 '22 at 16:48
0

In my case i just had to save the file in VSC.

0

In my case, I upgraded the dotnet version and in launch.json file I had to update the dotnet version folder in program path to get it working.

"program": "${workspaceFolder}/src/Project.SERVER/bin/Debug/net6.0/Project.Server.dll",
AzizStark
  • 1,390
  • 1
  • 17
  • 27