Closed bhalbright closed 9 months ago
@bhalbright, great question! Hot reload is an item on our backlog to investigate. We need to understand the technical challenges/blockers as well as the cost before we can commit to supporting it. Trust me, we would LOVE to, I just cannot commit at this time.
Thanks for your response @BigMorty. Hopefully this will make it in the tooling in the future! It would create a killer dev experience.
Would absolutely love this feature - we're starting to migrate more of project to Docker and using the Docker Compose Tooling (great job!) but having .NET Hot Reload support would significantly improve the dev inner loop by reducing the change feedback loop.
Would also love to see this feature - we're doing a lot of work with .NET 6, Docker and Dapr and this would really boost feedback loops / the dev cycle.
@JamesRandall Do you have a sample where you are doing dotnet watch
with .NET, Docker, and Dapr?
I think I'm close to getting it working? I've tried the following changes:
docker-compose.vs.debug.yml:
version: '3.4'
services:
test-service:
labels:
com.microsoft.visualstudio.debuggee.arguments: " watch run --additionalProbingPath c:\\.nuget\\packages --additionalProbingPath c:\\.nuget\\fallbackpackages --project \"C:\\app\\MyProject.csproj\" --urls http://+:80;https://+:443 --verbose"
DOCKERFILE (ending)
FROM build AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "watch", "C:\\app"]
The end result of this is that dotnet watch starts up in the container and even sees filesystem events:
dotnet watch โ dotnet-watch is configured to launch a browser on ASP.NET Core application startup.
dotnet watch โ Configuring the app to use browser-refresh middleware.
dotnet watch โ Refresh server running at ws://localhost:49160.
dotnet watch ๐ Started 'C:\Program Files\dotnet\dotnet.exe' '' with process id 412
dotnet watch โ Running dotnet with the following arguments: run --additionalProbingPath c:\.nuget\packages --additionalProbingPath c:\.nuget\fallbackpackages --urls http://+:80;https://+:443
dotnet watch ๐ Started
info: Microsoft.Hosting.Lifetime[14]
Now listening on: https://[::]:443
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Development
info: Microsoft.Hosting.Lifetime[0]
Content root path: C:\app\
dotnet watch โ Killing process 412
dotnet watch โ Process id 412 ran for 101011ms
dotnet watch โ Exited
dotnet watch โ File changed: C:\app\Pages\Index.razor
However, I hit the following msbuild failure when the watch tries to recompile:
C:\Program Files\dotnet\sdk\6.0.401\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3027: Could not copy "C:\app\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\MyProject.exe". Exceeded retry count of 10. Failed. [C:\app\MyProject.csproj]
C:\Program Files\dotnet\sdk\6.0.401\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3021: Unable to copy file "C:\app\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\MyProject.exe". The process cannot access the file 'C:\app\bin\Debug\net6.0\MyProject.exe' because it is being used by another process. [C:\app\MyProject.csproj]
Anyone have any thoughts on how I could work around this? Thanks!
I've done it using separate build stage
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS watch
WORKDIR /src
COPY . /src
ENTRYPOINT ["dotnet", "watch", "run", "--urls", "http://0.0.0.0:5000"]
Then using command to build the image:
docker build . --target watch -t app
And then running the image
docker run -p 5000:5000 -v $PWD/:/src -v $PWD/bin -v $PWD/obj app
the --urls
parameter is for setting up application for EXPOSE (ports parameter). It have to be 0.0.0.0
since the watched app needs to be visible outside container.
There are 3 mounted volumes:
$PWD/:/src
- mounts local files into container file system /src
directory, for watch command to observe local changes$PWD/bin
- mounts empty volume to project bin
directory, what removes problem of files being used$PWD/obj
- mounts empty volume to project obj
directory, what removes problem of files being usedOn a side note to what folks in here suggested and tried (good stuff by the way) - Would it be possible to support a middle ground for the time being?
I recently worked with a few other technologies in the Java / Kotlin space, and it seems like most of them don't go the full mile to support hot reload, they simply restart the application once files were changed. Basically dotnet watch.
Would it be possible to simply restart the container and reattach the debugger in a non-intrusive way? I think that would already go a long way of adding reload-style support
Our current fix is to open and run blazor seperatly from the rest of our docker build environment whenever we want to make any changes, I hope there is room in the schedule for this issue sooner than later.
We haven't forgot about this request and sure hope we can provide something down the road. So far, we spent some time investigating this and realized that it is a fairly large work item that also involves work in .NET and Debugger. Will keep you posted once we can prioritize and have more info to share.
very necessary for this feature!
I think I'm close to getting it working? I've tried the following changes:
docker-compose.vs.debug.yml:
version: '3.4' services: test-service: labels: com.microsoft.visualstudio.debuggee.arguments: " watch run --additionalProbingPath c:\\.nuget\\packages --additionalProbingPath c:\\.nuget\\fallbackpackages --project \"C:\\app\\MyProject.csproj\" --urls http://+:80;https://+:443 --verbose"
DOCKERFILE (ending)
FROM build AS final WORKDIR /app COPY --from=publish /app/publish . ENTRYPOINT ["dotnet", "watch", "C:\\app"]
The end result of this is that dotnet watch starts up in the container and even sees filesystem events:
dotnet watch โ dotnet-watch is configured to launch a browser on ASP.NET Core application startup. dotnet watch โ Configuring the app to use browser-refresh middleware. dotnet watch โ Refresh server running at ws://localhost:49160. dotnet watch ๐ Started 'C:\Program Files\dotnet\dotnet.exe' '' with process id 412 dotnet watch โ Running dotnet with the following arguments: run --additionalProbingPath c:\.nuget\packages --additionalProbingPath c:\.nuget\fallbackpackages --urls http://+:80;https://+:443 dotnet watch ๐ Started info: Microsoft.Hosting.Lifetime[14] Now listening on: https://[::]:443 info: Microsoft.Hosting.Lifetime[0] Application started. Press Ctrl+C to shut down. info: Microsoft.Hosting.Lifetime[0] Hosting environment: Development info: Microsoft.Hosting.Lifetime[0] Content root path: C:\app\ dotnet watch โ Killing process 412 dotnet watch โ Process id 412 ran for 101011ms dotnet watch โ Exited dotnet watch โ File changed: C:\app\Pages\Index.razor
However, I hit the following msbuild failure when the watch tries to recompile:
C:\Program Files\dotnet\sdk\6.0.401\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3027: Could not copy "C:\app\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\MyProject.exe". Exceeded retry count of 10. Failed. [C:\app\MyProject.csproj] C:\Program Files\dotnet\sdk\6.0.401\Microsoft.Common.CurrentVersion.targets(5097,5): error MSB3021: Unable to copy file "C:\app\obj\Debug\net6.0\apphost.exe" to "bin\Debug\net6.0\MyProject.exe". The process cannot access the file 'C:\app\bin\Debug\net6.0\MyProject.exe' because it is being used by another process. [C:\app\MyProject.csproj]
Anyone have any thoughts on how I could work around this? Thanks!
I just came back here and played around with this approach as well. Great idea! I ultimately ran into the same issue as you did, and the debugging experience is definitely not nice, but on paper this is already close to the desired behaviour.
Just a quick note I wanted to drop for everyone else who wanted to play around with this approach: You definitely need to use a proper SDK image as "base" in your Dockerfile, since the "dotnet" cli tool does not come with "dotnet watch" outside of sdk images.
This feature is a must-have
@giuseppe-terrasi , we are working on Hot Reload support. Current plan if all goes well is to have support for CTRL-F5 in 17.7 and F5 support in the 17.8 release.
@giuseppe-terrasi , we are working on Hot Reload support. Current plan if all goes well is to have support for CTRL-F5 in 17.7 and F5 support in the 17.8 release.
@dbreshears apologies if this is obvious somewhere - I'm on my phone, but is there a roadmap and estimated data for 17.7 and 17.8?
@dbreshears Just looked at 17.7 release notes, but no mention of changes part of docker tooling here. Right now I assume everything has been pushed for at least 17.8, right? (which should be for dotnet 8 release I assume too)
@ggirard07 I've just installed the 17.7 and tested it with a solution containing two Blazor Server side apps dockerized and a docker-compose project. Running the docker-compose project using CTRL+F5 and not only the hot reload button appeared but the app updated instantly after any change! Awesome!
In my case I was waiting for the F5 experience, potentially for 17.8, as I do most of my work on backend/WebAPI side ๐ Just wanted to check if progress was going as expected.
I just tested out 17.7 and can't get the feature to work via docker-compose. I have just published the sample app we used which caused me to seek out this repo and file the issue in March 2021
https://github.com/endjin/DaprMultiContainer
I'd love if the team could use this as a test case for the feature, as this type of solution is the one that could most benefit from hot reload (when you multiply up the number of services)
@HowardvanRooijen I've cloned your repo, and the hot reload works both on backend and frontend, updating both C# code and HTML code. Here is the Hot reload button while the docker-compose is running:
Hot reload is visible for us when we hit Ctrl+F5, and if we make a change to Summaries
(i.e. make them all upper case) we see Changes were successfully applied.
in the Hot Reload output window, but if you refresh https://localhost:50852/ you still have the old values returned. This behaviour has been repro'd by another developer who did the 17.7 upgrade. (@mikeevanslarah)
@HowardvanRooijen I mean, the changes appears also if I refresh the page
Any chance you could provide a Visual Studio "copy info"? Mine is:
Microsoft Visual Studio Enterprise 2022
Version 17.7.0
VisualStudio.17.Release/17.7.0+34003.232
Microsoft .NET Framework
Version 4.8.09032
Installed Version: Enterprise
Visual C++ 2022 00476-80000-00000-AA362
Microsoft Visual C++ 2022
ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools
ASA Service Provider 1.0
ASP.NET and Web Tools 17.7.265.7160
ASP.NET and Web Tools
ASP.NET Web Frameworks and Tools 2012 17.7.265.7160
For additional information, visit https://www.asp.net/
Azure App Service Tools v3.0.0 17.7.265.7160
Azure App Service Tools v3.0.0
Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 17.7.265.7160
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
C# Tools 4.7.0-3.23373.1+7829f6b85177e96de89bc67f32b61d74ac590f5a
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Command2 Extension 1.0
Command2 Visual Stuido Extension Detailed Info
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
GitHub Copilot 1.100.0.0 (v1.100.0.0@6ff082509)
GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.
GitHub Copilot Agent 1.100.306 (v1.100.0)
Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query
Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics
Microsoft Azure Tools for Visual Studio 2.9
Support for Azure Cloud Services projects
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
NuGet Package Manager 6.7.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
Razor (ASP.NET Core) 17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1
Provides languages services for ASP.NET Core Razor.
SQL Server Data Tools 17.7.9.2
Microsoft SQL Server Data Tools
ToolWindowHostedEditor 1.0
Hosting json editor into a tool window
TypeScript Tools 17.0.20628.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.7.0-3.23373.1+7829f6b85177e96de89bc67f32b61d74ac590f5a
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual F# Tools 17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143
Microsoft Visual F# Tools
Visual Studio Extension for SpecFlow 1.0
Visual Studio extension for working with SpecFlow projects and Gherkin feature files.
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
This is mine (it is in Italian but I don't think it matters. But I'm using the Community version):
Microsoft Visual Studio Community 2022
Versione 17.7.0
VisualStudio.17.Release/17.7.0+34003.232
Microsoft .NET Framework
Versione 4.8.09032
Edizione installata: Community
Visual C++ 2022 00482-90000-00000-AA816
Microsoft Visual C++ 2022
ADL Tools Service Provider 1.0
This package contains services used by Data Lake tools
ASA Service Provider 1.0
ASP.NET and Web Tools 17.7.265.7160
ASP.NET and Web Tools
Azure Data Lake Tools for Visual Studio 2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio
Azure Functions and Web Jobs Tools 17.7.265.7160
Azure Functions and Web Jobs Tools
Azure Stream Analytics Tools for Visual Studio 2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio
Bridge to Kubernetes 0.1
Bridge to Kubernetes per Visual Studio 2019
Common Azure Tools 1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
Debug dump di base Linux 1.0.9.33920
Abilita il debug dei dump di base Linux.
Entity Framework Core Power Tools 2.5
Aggiunge strumenti di design-time per EF Core al menu contestuale del progetto nella finestra Esplora soluzioni di Visual Studio.
Estensione VSPackage 1.0
Informazioni dettagliate sull'estensione VSPackage di Visual Studio
Extensibility Message Bus 1.4.34 (main@d5ab18b)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.
Gestione pacchetti NuGet 6.7.0
Gestione pacchetti NuGet in Visual Studio. Per altre informazioni su NuGet, visitare il sito Web https://docs.nuget.org/
Microsoft Azure Hive Query Language Service 2.6.5000.0
Language service for Hive query
Microsoft Azure Stream Analytics Language Service 2.6.5000.0
Language service for Azure Stream Analytics
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
Mono Debugging for Visual Studio 17.7.27 (547ea6f)
Support for debugging Mono processes with Visual Studio.
OpenT4EditorSettingsCommand Extension 1.0
OpenT4EditorSettingsCommand Visual Studio Extension Detailed Info
PHP Tools for Visual Studio 1.74.18199.2022
PHP Tools extend Visual Studio with a set of features to build PHP applications more efficiently. It makes code more readable, easier to navigate, and clean.
Razor (ASP.NET Core) 17.7.3.2333001+0ab18affdf2a37647768d0e25f5f021bee6257a1
Fornisce servizi di linguaggio per ASP.NET Core Razor.
SQL Server Data Tools 17.7.9.2
Microsoft SQL Server Data Tools
Strumenti C# 4.7.0-3.23373.1+7829f6b85177e96de89bc67f32b61d74ac590f5a
Componenti di C# usati nell'IDE. A seconda del tipo e delle impostazioni del processo, รจ possibile che venga usata una versione diversa del compilatore.
Strumenti del Servizio app di Azure versione 3.0.0 17.7.265.7160
Strumenti del Servizio app di Azure versione 3.0.0
Strumenti di Visual Basic 4.7.0-3.23373.1+7829f6b85177e96de89bc67f32b61d74ac590f5a
Componenti di Visual Basic usati nell'IDE. A seconda del tipo e delle impostazioni del processo, รจ possibile che venga usata una versione diversa del compilatore.
Strumenti TypeScript 17.0.20628.2001
Strumenti TypeScript per Microsoft Visual Studio
ToolWindowHostedEditor 1.0
Hosting json editor into a tool window
Visual C++ per lo sviluppo di applicazioni Linux 1.0.9.33920
Visual C++ per lo sviluppo di applicazioni Linux
Visual F# Tools 17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
Sviluppo assistito conl'intelligenza artificiale per Visual Studio.
VisualStudio.DeviceLog 1.0
Informazioni sul pacchetto
VisualStudio.Mac 1.0
Mac Extension for Visual Studio
Xamarin 17.7.0.214 (d17-7@a69bacb)
Estensione di Visual Studio per consentire lo sviluppo per Xamarin.iOS e Xamarin.Android.
Xamarin Designer 17.7.3.9 (remotes/origin/d17-7@796d191def)
Estensione di Visual Studio per abilitare gli strumenti di Xamarin Designer in Visual Studio.
Xamarin Templates 17.7.21 (150ec9f)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.
Xamarin.Android SDK 13.2.1.2 (d17-5/a8a26c7)
Xamarin.Android Reference Assemblies and MSBuild support.
Mono: d9a6e87
Java.Interop: xamarin/java.interop/d17-5@149d70fe
SQLite: xamarin/sqlite/3.40.1@68c69d8
Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d
Xamarin.iOS and Xamarin.Mac SDK 16.4.0.5 (191fe02ea)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
@giuseppe-terrasi after some more experimenting, it appears that Hot Reload is working in general.
We were getting confused because we were testing by updating the values in private static readonly string[] Summaries
in WeatherForecastController
and not seeing the changes propagate. However I noticed that this also happens when using Hot Reload outside of Docker Tools.
Other changes to code are propagating on save as expected.
@MikeEvansLarah great! The hot reload requires a rebuild based on what you update and static values are one of these cases ;)
Thanks for sanity checking @giuseppe-terrasi!
Another thing we discovered is that the changelog in this repo is out of date, but the one in the nuget package is up-to-date, and contains some useful info:
https://www.nuget.org/packages/Microsoft.VisualStudio.Azure.Containers.Tools.Targets#readme-body-tab
@giuseppe-terrasi I tried cloning the above repo but I don't seem to be able to run hot reloading either.
This is my VS info:
Microsoft Visual Studio Community 2022
Version 17.7.3
VisualStudio.17.Release/17.7.3+34024.191
Microsoft .NET Framework
Version 4.8.09037
Installed Version: Community
Visual C++ 2022 00482-90000-00000-AA618
Microsoft Visual C++ 2022
ASP.NET and Web Tools 17.7.273.65229
ASP.NET and Web Tools
Azure App Service Tools v3.0.0 17.7.273.65229
Azure App Service Tools v3.0.0
C# Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Linux Core Dump Debugging 1.0.9.34018
Enables debugging of Linux core dumps.
Microsoft JVM Debugger 1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines
NuGet Package Manager 6.7.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/
TypeScript Tools 17.0.20628.2001
TypeScript Tools for Microsoft Visual Studio
Visual Basic Tools 4.7.0-3.23416.8+43b0b05cc4f492fd5de00f6f6717409091df8daa
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.
Visual C++ for Linux Development 1.0.9.34018
Visual C++ for Linux Development
Visual F# Tools 17.7.0-beta.23314.10+e612cf93b989503c89e3a5830090062b7ab5e143
Microsoft Visual F# Tools
Visual Studio IntelliCode 2.2
AI-assisted development for Visual Studio.
Am I missing having installed something?
@nicleary Just double checking you're doing Ctrl+F5 to start without debugging?
@HowardvanRooijen Ah I see, I didn't realize I needed to do that. Thank you!
Hello! Is the same process valid on .NET 8 & VisualStudio 17.8? I have access to my app with hot reload by launching the container with CTRL + 5, but i don't have the same behavior when I launch it with docker-compose up -d
, is that normal? Thanks in advance!
@dgo-gco This is a feature related to Visual Studio so if you run the project using docker-compose up -d
from the terminal it is normal that the hot reload doesn't work.
In VS 2022 17.7 basic Hot Reload support was added for Ctrl+F5 and now in 17.8 basic Hot Reload support was extended to F5.
@ggirard07 I've just installed the 17.7 and tested it with a solution containing two Blazor Server side apps dockerized and a docker-compose project. Running the docker-compose project using CTRL+F5 and not only the hot reload button appeared but the app updated instantly after any change! Awesome!
@NCarlsonMSFT
Is this still the case? I'm on VS 17.8.6, and hot reload does not work at all for our Blazor Server projects using docker compose launch profiles (F5 and Ctrl+F5).
Hot Reload output says "No changes were found."
Edit: I should clarify the projects aren't "Blazor Server", but the .NET 8 Blazor Web App with (global) interactive server render mode. Is this not supported yet?
@JonHodgins just created a new .NET 8 Blazor Web App with (global) interactive server render mode, Ctrl+F5ed and edited Home.razor. The hot reload did work for me.
Is there any news on hot reload while debugging? I am trying this feature on VS 17.11.2 and .NET8 application launched using docker compose. If I launch without debugging (CTRL+F5) hot reload works fine but when using debug (F5) it detects changes but it does not update the application.
Forgive me for using this board just to ask a question, wasn't sure of a better place to ask.
https://devblogs.microsoft.com/dotnet/update-on-net-hot-reload-progress-and-visual-studio-2022-highlights/ states "the basic Hot Reload experience works with most types of .NET apps and framework versions". From the best I can tell, that does not include running .NET apps using the Visual Studio 2022 docker-compose tooling. I tried with VS 2022 Docker tools/.NET 6 and just get an error "Applying source changes while the application is running is not supported by the runtime."
Just curious, is this ever planned to be supported? I know there's some docs about live refreshing razor pages, but I'm not using razor pages.
As an aside, I've also tried playing around with dotnet watch run by manipulating labels in docker-compose.vs.debug.yml (https://docs.microsoft.com/en-us/visualstudio/containers/docker-compose-properties?view=vs-2022#docker-compose-file-labels) with limited success. I can make the app reload but it seems to break the debugging experience, unless I'm not doing it right.