mcintyre321 / EmbeddedResourceVirtualPathProvider

A custom VirtualPathProvider for IIS - load views and assets from Embedded Resources in referenced assemblies
http://www.adverseconditionals.com/2011/07/portable-aspnet-code-using.html
MIT License
63 stars 42 forks source link

How do I get the VPP to pick-up changes without restarting my web app? #42

Closed underctrl closed 4 years ago

underctrl commented 4 years ago

I have two projects:

/Project1 is a C# MVC web app
/Project2 is just a collection of helper classes, with some Views and JavaScript files

(Note that I actually have a few web projects that will share the files from Project2 -- I'm just trying to keep this example simple to grok...)

I've setup EmbeddedResourceVirtualPathProvider in Project1 like this, and it works (my site finds the files embedded within the Project2 DLL...)

System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceVirtualPathProvider.Vpp {
    // I assume this path is relative from "/Project1/bin", where all the DLLs are after running the site...?
    { typeof (AssemblyIdentifier).Assembly, @"..\..\Project2\bin\Debug" }
});

My problem is that if I make changes to anything in Project2 and build only that project, the changes are not picked-up by Project1 auto-magically like I thought they were supposed to be. It also works this way no matter what path string I give -- and I've tried several, like @"..\..\Project2\bin\Debug\Project2.dll", C:\Project2\bin\Debug, and even a path to a folder that doesn't exist -- but it appears to always use the DLL from Project1's bin folder (I assume, because it has to be getting it from somewhere...)

How can I set this up so that I don't have to rebuild and rerun my website everytime I make changes to files in Project2? Thanks!

mcintyre321 commented 4 years ago

It's been years since I've looked at this I'm afraid, but I think it's "../SomeProject2"

bafsar commented 4 years ago

My answer is not related to VPP directly but I assume it's being useful for you.

On server, an Mvc project load assemblies from its bin folder. But, the server (window server) doesn't use these files all time. After application start, the files in bin folder copies to the shadow folder. But server watches the bin folder to reflects changes. Unfortunately, the server doesn't watch another folders. To do that, you can set up a FileSystemWatcher. While running this class's instance, the file changes in the folder that you gave being watched. So, after you build project2, all changes will be reflected after a few seconds...

mcintyre321 commented 4 years ago

Here's the critical line: https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider/blob/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/EmbeddedResourceVirtualPathProvider/EmbeddedResource.cs#L51

The path is relative from "/Project1", so "../Project2"

underctrl commented 4 years ago

@bafsar Thanks, I didn't know about the FileSystemWatcher -- That's good to know...

@mcintyre321 Thank you, I finally got this working -- I just needed to know that the path is relative from/to the project folders, not the bin folders...