Moved from https://github.com/aspnet/Docs/issues/7707. See that issue for more context. Originally opened by @djhmateer. /cc: @mkArtakMSFT
I've been unsuccessful getting Edit and Continue mentioned above working.
Windows 10 host to Linux container using ASP.NET Core 2.1 being able to update a .cshtml and see the changes in the browser (after doing F5 in browser) without doing a Ctrl F5 in Visual Studio.
Details of what I did are in: https://stackoverflow.com/questions/51441893/visual-studio-2017-docker-edit-and-continue
Document Details
⚠Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
- ID: d772b44a-b5f3-5a10-4ea3-4463bdcf90bb
- Version Independent ID: 5847cdf8-1823-7740-6e43-030902b26ad8
- Content: Visual Studio Tools for Docker with ASP.NET Core
- Content Source: aspnetcore/host-and-deploy/docker/visual-studio-tools-for-docker.md
- Product: aspnet-core
- GitHub Login: @spboyer
- Microsoft Alias: scaddie
The issue is an side effect of the way ActionDescriptorCollectionProvider listens for changes. On a Linux based docker container, the file system watching is passive i.e. IChangeToken.ActiveChangeCallbacks = false. The ChangeToken.OnChange pattern that we rely in here does not account for passive IChangeToken instances. A possible fix for this would be to stash the result of GetCompositeChangeToken() and query if it's different. Alternatively, we could modify ActionDescriptorCollectionProvider.ActionDescriptors to always update the collection on demand. E.g.
```C#
public ActionDescriptorCollection ActionDescriptors
{
get
{
if (_collection == null || _changeToken.HasChanged)
{
UpdateCollection();
_changeToken = GetChangeToken();
}
return _collection;
}
}
```
@djhmateer, you could try using a custom implementation of IActionDescriptorCollectionProvider as a workaround until we've addressed this in the framework. Here's what you'd do:
C#
services.AddSingleton<IActionDescriptorCollectionProvider, PollingActionDescriptorCollectionProvider>();
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
I was able to verify locally that this addressed the issue you were seeing.
Many thanks @pranavkm. The https://gist.github.com/pranavkm/10759ca15205c49e94ecd8739ae3a44a link gave me a compile error: Method must have a return type. I'm not quite sure how to resolve.
public ActionDescriptorCollectionProvider1(
IEnumerable
IEnumerable
@djhmateer Looks to me like that should be a constructor. Try the following constructor signature:
public PollingActionDescriptorCollectionProvider (
IEnumerable<IActionDescriptorProvider> actionDescriptorProviders,
IEnumerable<IActionDescriptorChangeProvider> actionDescriptorChangeProviders)
Yup, @scottaddie got it right. Fixed the gist with the correct type name.
@scottaddie and @pranavkm much appreciated - yes I can confirm that this works. Very interesting and thank you for the explanation.
Most helpful comment
@djhmateer, you could try using a custom implementation of
IActionDescriptorCollectionProvideras a workaround until we've addressed this in the framework. Here's what you'd do:C# services.AddSingleton<IActionDescriptorCollectionProvider, PollingActionDescriptorCollectionProvider>(); services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);I was able to verify locally that this addressed the issue you were seeing.