Git Product home page Git Product logo

mcintyre321 / embeddedresourcevirtualpathprovider Goto Github PK

View Code? Open in Web Editor NEW
63.0 63.0 42.0 207 KB

A custom VirtualPathProvider for IIS - load views and assets from Embedded Resources in referenced assemblies

Home Page: http://www.adverseconditionals.com/2011/07/portable-aspnet-code-using.html

License: MIT License

C# 88.84% ASP 5.92% JavaScript 1.38% Pascal 3.85%
asp-net c-sharp embedded-resources

embeddedresourcevirtualpathprovider's People

Contributors

bitdeli-chef avatar dashue avatar djechelon avatar evil-shrike avatar hakksor avatar mcintyre321 avatar miguelhughes avatar mycroes avatar robbiecooray avatar thorgeir avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

embeddedresourcevirtualpathprovider's Issues

Locked assembly file after Publish

Hello again my friend
we just upgraded from 1.3.23 to 1.3.48 and still we experience this

Solution:

  • Core (with base css, js and cshtml files) proj
  • Specific (overrides some css, js or cshtml files) proj

Our Homepage loads content from both Specific and Core projs, thanks to VPP.

Once i try to login, the page suddendly becomes white and i get this error in eventlog.xml

`IIS APPPOOL\SpecificProjPathConfigurationErrorsExceptionCould not load file or assembly 'CoreProj' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)
at System.Web.Configuration.CompilationSection.LoadAllAssembliesFromAppDomainBinDirectory()
at System.Web.Configuration.CompilationSection.LoadAssembly(AssemblyInfo ai)
at System.Web.Compilation.BuildManager.GetReferencedAssemblies(CompilationSection compConfig)
at System.Web.Compilation.BuildManager.GetPreStartInitMethodsFromReferencedAssemblies()
at System.Web.Compilation.BuildManager.CallPreStartInitMethods(String preStartInitListPath, Boolean& isRefAssemblyLoaded)
at System.Web.Compilation.BuildManager.ExecutePreAppStart()
at System.Web.Hosting.HostingEnvironment.Initialize(ApplicationManager appManager, IApplicationHost appHost, IConfigMapPathFactory configMapPathFactory, HostingEnvironmentParameters hostingParameters, PolicyLevel policyLevel, Exception appDomainCreationException)

Could not load file or assembly 'CoreProj' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)
at System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean forIntrospection)
at System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)
at System.Web.Configuration.CompilationSection.LoadAssemblyHelper(String assemblyName, Boolean starDirective)

`

This happens only sometimes after publishing. Do you think it has something to do with you library?

Thanks

Trying to get working with MVC 4

Hello....not sure if this is an issue...more of a request for assistance. Trying to use the library to use as part of a MVC Contrib portalable area.

I set your library up in the DLL for the portable area and put the JS files in the scripts directory. When I try adding the MVC Portable area DLL to the main MVC project (in an Area)...i am get a error with the following test JQuery ($ is undefinded)

@model dynamic

<title></title> <script src="/Scripts/jquery-1.8.2.js" ></script>

Click on this paragraph.

<script>
$(document).ready(function () {
    $("p").click(function () {
        alert("The paragraph was clicked.");
    });
});
</script>

Any help is appreciated

during development workflow?

hi,
great work, you have mentioned in the readme the following
"You can also map assemblies to their location on disk, so they can be refreshed when you edit the files during development."

currently i am using this
http://virtualtemplates.codeplex.com/

the est part about it is while i am in development, i can work with files on desk, in this way if i update any images, or any files, i don't have to recompile the referenced project, so all what i have to do is just to reference the project library and once i am done i just upload the dll to the website.

i think this is the same as your statement above, if i am correct, could you please tell me what lines of code should i add to have the above functionality, as it is not mentioned in the Readme.

thanks in adavaced

Publish Precompiled project not working

Publishing a web app that has the Precompile during publishing option ticked,
causes any embedded resources from other projects/dlls to be missing - tested with .cshtml, .css, .js files.

Another minor issue is with bundling,
the {version} tag used for example by the default jquery bundle stops working as soon as EmbeddedResourceVirtualPathProvider is added to a project

Usage with MVC bundles

Hello,

First thanks for this great project, it has helped me a lot. But now I ran into a problem I don't know how to solve...

I'm trying to use EmbeddedResourceVirtualPathProvider as VirtualPathProvider for MVC bundles..

However I have a problem that my bundles are not refreshing when I edit files.

Here's my usage:
BundleTable.VirtualPathProvider = new Vpp(BundleTable.VirtualPathProvider)
{
{typeof (BundleConfig).Assembly, @""},
};

It does not work if file is embeded or not... Not sure on how to solve this issue.

Thanks for any help !

Using "Enabling debugging for embedded razor views" doesn't works

When I used the technique described in "Enabling debugging for embedded razor views".
If I put a breakpoint on the host constructor when a embedded Razor page is called, GetResourceFromVirtualPath() does return me a resource but resource.Filename is always null.

Bundling and filenames with dots

Hi there,

I know I've read this somewhere in an article about this project - but I can't seem to find it now so I thought I would put it on here.

I am running into issues when attempting to use the VPP with bundling. In particular, with files from commonly used libraries (jQuery and Kendo).

`var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies()
.Cast()
.Where(a => a.GetName().Name.StartsWith("MyNamespace"));

        BundleTable.VirtualPathProvider = new Vpp(assemblies.ToArray());

        bundles.Add(new ScriptBundle("~/bundles/kendo").Include(
          "~/Scripts/kendo/2017.2.504/kendo.all.min.js",
          "~/Scripts/kendo/2017.2.504/kendo.aspnetmvc.min.js"));`

This is failing due to the dots in the javascript filenames. I should point out that these scripts aren't actually in my class library, but are instead in my local MVC project.

I have downloaded the source code and attempted to debug this myself, but am not really getting anywhere. I can see that if I rename the files to not have any dots, the Vpp.GetFile method is called and everything works from there. If the dots are there, this method never gets called.

Why does it not get called? Where is the code that is preventing this?

Thanks

EmbeddedResourcePath Regex Parser Bug

Take FormFactory as example, following step 2 in this link adding

<link href="/Content/FormFactory/FormFactory.css" rel="stylesheet" type="text/css"/>

EXPECT:      FormFactory.css to load correctly
ACTUAL:      404 not found

The embedded resource namespace is FormFactory.Content.FormFactory.FormFactory.css

The EmbeddedResourcePath Regex Parsing code on line 17 incorrectly produce directory name as Content.FormFactory and therefore I have to use the url becomes ~/Content.FormFactory/FormFactory.css

SUGGEST to fix this simply by replacing any dots with slashes on the parsed directory name on line 43

VPP Not Working on Integrated IIS7 Azure

Hi.

We have deployed our solution on Azure using pre-compilation option while publishing, and none of the resources from the DLL (so i'm talking about the Embedded resource: may they be js, css or cshtml) get loaded.

Without pre-compiling, it works great.

Are you aware of this issue?

Thanks

404 with .svg and .woff

I get a 404.0 in IIS 7.5 when trying to load a svg/woff file with EmbeddedResourceVirtualPathProvider.
I've added the mimetype in web.config
< system.webServer>
< staticConfent >
< remove fileExtension=".svg" />
< mimeMap fileExtension=".svg" mimeType="image/svg+xml" />
< remove fileExtension=".svgz" />
< mimeMap fileExtension=".svgz" mimeType="image/svg+xml" />
< remove fileExtension=".woff" />
< mimeMap fileExtension=".woff" mimeType="application/font-woff" />
</ staticContent>
</ system.webServer>
Png, js, cshtml all work fine.

Missing strong name

Hi,

could you sign the assembly with a strong name please?

Best regards

Boris

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

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!

Does not work in IIS

Hi, I have a problem when I deployed it on my local iis, "The view 'Frontend/Default' or its master was not found or no view engine supports the searched locations. The following locations were searched:"
any suggestions on how to fixt this?

Thanks,
Renz

Please remove content scripts

Hi.
(It's slightly related to issue #35 but more general)

Currently the lib has a couple of content script which are processed on install:

  • App_Start/EmbeddedResourceVirtualPathProviderStart.cs.pp - creates a AppStart script which register EmbeddedResourceVirtualPathProvider with all assemblies
  • web.config.transform - adds StaticFileHandler into web.config

I understand it could be handy for some people to have auto created such files. But in general it a bad idea. It blindly adds what I didn't ask: scan all (!)non system assemblies for embedded resources, add a http handlers.
The former is usually unneeded as you'd better specify assemblies to scan explicitly
The latter is even more bad thing. I can't understand why a lib should add such settings at all. But particularly this handler overwrites headers for static content specified in web.config.
For example I have staticContent/clientCache in my web.cofnig with httpExpires="Fri, 31 Dec 1999 00:00:00 GMT" - it tells browsers do not cache anything. It's very important during development. StaticFileHandler overrides this settings and set current timestamp in Expire header.

Sure I can remove all this stuff manully. But please take into account that the lib can be a transitive dependency. So people even can be not installing particularly this lib but some other depending on it. And they will get these arguable settings/defaults.

App_Code instead of App_Start

I have just found that, after downloading package from NuGet and contrary to documentation, the RegisterVirtualPathProvider is created in App_Code rather than App_Start, and Global.asax.cs is not updated to call RegisterVirtualPathProvider.AppInitialize().

I was trying to look in the code where the cs file is created during installation to submit a fix. I'm not a great expert in NuGet, I would be glad to contribute for fixing this 😄

hyphens and underscores

Hi! great work on this plugin, very neccessary.
Do you know if this supports embedded resources with files and folder names containing dashes "-" ?
I have some, and looking at the generated dll, the hyphens seem to be converted to underscores "_". I don't see any replacements in the code from _ back to - ...
Have I got this correctly or am I missing something?

this post:
http://social.msdn.microsoft.com/forums/vstudio/en-US/632d6914-8c90-450e-8ea0-fa60d2c3b6b6/manifest-name-for-embedded-resources
Also reports this modification in the embedded resoure name.
Are you familiar with this issue? Is there a workaround?

Thanks for your help!

Load views from different assemblies based the URL

I want to have URLs like
localhost:64296/SomeAssemblyName/Home/Index
and
localhost:64296/OtherAssemblyName/Home/Index
which can load my views from different assemblies depends on its URL

Could you give me a hint how I can Achieve it?

Split the package onto two ones: core and bootstrapper

Hi.

I want to use the lib as a dependency in my lib but I already have other startup code in that lib (registered callback via WebActivator) so additional App_Start script is unneeded. Moreover EmbeddedResourceVirtualPathProvider brings another dependency into app project (WebActivatorEx) which is also unneeded.
What I'd suggest is to split the package onto two ones: the first one - "core" - is implementation (lib) without any dependencies and content scripts and and second one - "bootstrap" - is a package with dependency on "core" package, WebActivatorEx and content scripts.

What do you think?

Simple support for a little diagnostics

Hey, good work on this lib!
Wanted to share a thought I had just recently.
I'm currently doing this and it works.

        var modules = BuildManager.GetReferencedAssemblies()
            .Cast<Assembly>()
            .Where(assembly => assembly
                .GetTypes()
                .Any(x => x.IsClass && x.GetInterfaces().Contains(typeof (IModuleConfiguration))));

        var virtualPathProvider = new Vpp2(modules.ToArray());
        {
            //you can do a specific assembly registration too. If you provide the assemly source path, it can read
            //from the source file so you can change the content while the app is running without needing to rebuild
            //{typeof(SomeAssembly.SomeClass).Assembly, @"..\SomeAssembly"} 
        };

        logger.Info(" Loading the following modules");
        foreach (var item in modules)
        {
            logger.Info(item.GetName().Name);
        }
        logger.Info(" Finished loading modules");

        logger.Info(" Listing embedded module resources");
        foreach (var item in virtualPathProvider.resources)
        {
            logger.Info(item.Key);
        }
        logger.Info(" Finished listing the embedded module resources");

        HostingEnvironment.RegisterVirtualPathProvider(virtualPathProvider);

However if VPP exposed the names of the loaded modules and resources this woul dbe easier.
VPP2 is just VPP with the resouces property set to public.

Looking forward to your thoughts

Virtual resources cannot be cached by browser

You'll notice that any virtual resources do not output any cache control headers to the browsers while their static equivalents will. Apparently this can be fixed by adding to EmbeddedResourceVirtualFile.Open():

HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.Public);
HttpContext.Current.Response.Cache.AppendCacheExtension("max-age=86400");

Of course, it would be best if the max-age were configurable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.