Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

wes-sleeman
Copy link
Contributor

Add an environment variable to permit deterministic and user-controlled selection of the browser refresh port when using the hot reload feature of dotnet watch.

This PR adds a new environment variable named DOTNET_WATCH_AUTO_RELOAD_WS_PORT to provide the other half of the functionality provided by DOTNET_WATCH_AUTO_RELOAD_WS_HOSTNAME. This is particularly useful in situations such as container-based development workflows as it allows for specific port forwarding rules to be hard-coded in advance.

First-time contribution, so any tips on how I can get this backported as far as we usually support would be appreciated.

Closes dotnet/aspnetcore#33823

Copy link
Contributor

github-actions bot commented Sep 4, 2025

This PR is targeting main, which is now for .NET 11-facing work. If you intended to target .NET 10, either retarget this PR to release/10.0.1xx or make sure you backport the change to release/10.0.1xx after merging. See #50394 for more details.

@github-actions github-actions bot added the Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch label Sep 4, 2025
Copy link
Contributor

Thanks for your PR, @@wes-sleeman.
To learn about the PR process and branching schedule of this repo, please take a look at the SDK PR Guide.

@wes-sleeman
Copy link
Contributor Author

@dotnet-policy-service agree

@wes-sleeman
Copy link
Contributor Author

@dotnet/domestic-cat
I think this is ready for review and (hopefully) merge. Let me know if anything else needs to be done to get this ready.

@baronfel
Copy link
Member

baronfel commented Sep 4, 2025

@wes-sleeman All Watch stuff goes to @tmat, so we'll wait for him to chime in.

Thanks for making your contribution! We're technically still open for SDK-level changes for a couple more weeks, so it's possible this could make it to .NET 10. That would require a backport (which we can trigger) once this merges - since main is technically .NET 11 already!

It's very unlikely that we would backport this to 8.x or 9.x SDKs without a really compelling customer use case, or some kind of external partner to justify the work + ongoing maintenance. The SDK is mostly a fix-forward kind of component for features - majorly-impactful bug fixes and security updates are the main category of thing that would be backported.

@wes-sleeman
Copy link
Contributor Author

wes-sleeman commented Sep 4, 2025

@baronfel, thanks for the quick reply! Would enjoy this making it into .NET 10 as this has been a blocker for me leveraging .NET with my team at work (enough to make me file this PR in my spare time!), so happy to hear there's a chance on that.

@wes-sleeman wes-sleeman requested a review from baronfel September 4, 2025 19:28
@tmat
Copy link
Member

tmat commented Sep 10, 2025

@wes-sleeman Would you mind updating your PR to resovle the conflicts?

You'll need to add a new property to EnvironmentOptions flow it as a parameter to BrowserRefreshServer constructor.
I'd also prefer the type of this property to be int? (optional port), not string.

@wes-sleeman
Copy link
Contributor Author

@tmat Sorry for the delay! Only just got around to resolving this. Looks like you re-architected this whole feature a few days ago. I've merged the changes in sensibly and added the necessary helper function to make it an int? as requested. Let me know if you run into any other trouble with it. :)

@tmat
Copy link
Member

tmat commented Sep 14, 2025

@wes-sleeman Thanks for your effort!

@tmat tmat merged commit c2427dd into dotnet:main Sep 14, 2025
27 checks passed
@tmat
Copy link
Member

tmat commented Sep 14, 2025

/backport to release/10.0.1xx

1 similar comment
@tmat
Copy link
Member

tmat commented Sep 15, 2025

/backport to release/10.0.1xx

Copy link
Contributor

Started backporting to release/10.0.1xx: https://github.com/dotnet/sdk/actions/runs/17746309610

Copy link
Contributor

@tmat backporting to "release/10.0.1xx" failed, the patch most likely resulted in conflicts:

$ git am --3way --empty=keep --ignore-whitespace --keep-non-patch changes.patch

Applying: Added port selection logic to the browser refresh script
Using index info to reconstruct a base tree...
A	src/BuiltInTools/dotnet-watch/Browser/BrowserRefreshServer.cs
Falling back to patching base and 3-way merge...
CONFLICT (modify/delete): src/BuiltInTools/dotnet-watch/Browser/BrowserRefreshServer.cs deleted in HEAD and modified in Added port selection logic to the browser refresh script.  Version Added port selection logic to the browser refresh script of src/BuiltInTools/dotnet-watch/Browser/BrowserRefreshServer.cs left in tree.
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 Added port selection logic to the browser refresh script
Error: The process '/usr/bin/git' failed with exit code 128

Please backport manually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-AspNetCore RazorSDK, BlazorWebAssemblySDK, dotnet-watch Area-Watch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Can't set a static port/endpoint of auto reload script when running dotnet watch run.
3 participants