Reputation: 6196
I'm working on an ASP.NET Core application using Visual Studio which is hosted with Docker.
To do this I went through the usual steps of Enabling Docker Support when I created the project, and - since I'm using other containers - adding orchestration support, by way of a separate docker-compose project which again I did through the usual Add -> Container Orchestration Support menu.
I'm now able to start up the containers locally using the Debug button in VS, using the 'Docker Compose' configuration. I can hit breakpoints, etc.
However, in order to actually modify the code and try it, I have to restart the whole process (i.e. compose up and down) the whole system each time. This is already very time consuming (over a minute) for changes to a project which itself builds in seconds.
I've seen some mentions of Edit and Continue being possible in C# with Docker, but I don't seem to be able to do this. The editor is read-only, and I can only modify by bringing the system down. And even if I could, building the project again requires VS to come out of debugging (which again would bring the system down).
Can anyone point me in the right direction for this? I've found some guides, but they're several years old and tend to refer to features in VS / .NET Core which appear to be outmoded.
Upvotes: 3
Views: 651
Reputation: 1022
I have also been struggling with this, being new to Docker. However I have a feeling the problem is more related to .NET Core 3/Visual Studio 2019, than Docker.
I managed to get static files and razor files to reflect changes immediately by referring to:
The parts I did from the above link was: Made sure that the .NET Core cross-platform development workload was loaded for my visual studio 2019. (Opened visual studio installer, modified visual studio 2019 and ticked the .NET Core coss-platform development workload and updated).
I then discovered that when the docker website was running, changing a static css file did immediately get reflected. (Note: this may have been working before installing this update). But razor changes still did not. To fix this, I had to add the following Nuget Package:
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation
And then add AddRazorRuntimeCompilation() to Startup.cs
services.AddControllersWithViews().AddRazorRuntimeCompilation();
Then when starting docker, changes to Razor pages are now also reflected immediately. However still cannot get C# changes to work.
But there seem to be issues out there with .NET Core 3 and edit and continue. Maybe when they are resolved, it will also work with Docker Compose. https://github.com/aspnet/AspNetCore/issues/14712
Upvotes: 1