├── .gitignore ├── .vs └── config │ └── applicationhost.config ├── EmbeddedResourceVirtualPathProvider.sln ├── EmbeddedResourceVirtualPathProvider ├── .gitignore ├── EmbeddedResource.cs ├── EmbeddedResourceCacheControl.cs ├── EmbeddedResourcePath.cs ├── EmbeddedResourceVirtualDirectory.cs ├── EmbeddedResourceVirtualFile.cs ├── EmbeddedResourceVirtualPathProvider.csproj ├── Logger.cs ├── Properties │ └── AssemblyInfo.cs ├── Vpp.cs └── packages.config ├── LICENSE.md ├── NugetTestWebProject ├── .gitignore ├── App_Start │ └── EmbeddedResourceVirtualPathProviderStart.cs ├── Default.aspx ├── Default.aspx.cs ├── Default.aspx.designer.cs ├── NugetTestWebProject.csproj ├── Properties │ └── AssemblyInfo.cs ├── Web.Debug.config ├── Web.Release.config ├── Web.config ├── alert2.js └── packages.config ├── README.markdown ├── TestResourceLibrary ├── 3rd3Party │ ├── 3select2-3.4.5 │ │ └── select2.js │ └── hammer.js-1.0.10 │ │ └── hammer.js ├── Marker.cs ├── Properties │ └── AssemblyInfo.cs ├── Scripts │ └── alert-1.12.34567.min.js ├── TestResourceLibrary.csproj ├── alert.js └── alert2.js ├── TestWebProject ├── App_Start │ └── EmbeddedResourceVirtualPathProviderStart.cs ├── Default.aspx ├── Default.aspx.cs ├── Default.aspx.designer.cs ├── Global.asax ├── Global.asax.cs ├── Properties │ └── AssemblyInfo.cs ├── TestWebProject.csproj ├── Web.Debug.config ├── Web.Release.config ├── Web.config └── alert2.js ├── nuget ├── EmbeddedResourceVirtualPathProvider.Core │ ├── EmbeddedResourceVirtualPathProvider.Core.nuspec │ └── lib │ │ └── net40 │ │ └── placeholder.txt └── EmbeddedResourceVirtualPathProvider │ ├── EmbeddedResourceVirtualPathProvider.nuspec │ └── content │ ├── App_Start │ └── EmbeddedResourceVirtualPathProviderStart.cs.pp │ └── web.config.transform └── packages ├── EmbeddedResourceVirtualPathProvider.1.3.26 ├── EmbeddedResourceVirtualPathProvider.1.3.26.nupkg ├── content │ ├── App_Start │ │ └── EmbeddedResourceVirtualPathProviderStart.cs.pp │ └── web.config.transform └── lib │ └── net40 │ ├── EmbeddedResourceVirtualPathProvider.dll │ ├── EmbeddedResourceVirtualPathProvider.pdb │ └── placeholder.txt ├── Microsoft.Web.Infrastructure.1.0.0.0 ├── Microsoft.Web.Infrastructure.1.0.0.0.nupkg └── lib │ └── net40 │ └── Microsoft.Web.Infrastructure.dll ├── WebActivator.1.4.1 ├── WebActivator.1.4.1.nupkg └── lib │ └── net40 │ └── WebActivator.dll ├── WebActivatorEx.2.0.3 ├── WebActivatorEx.2.0.3.nupkg └── lib │ └── net40 │ └── WebActivatorEx.dll └── repositories.config /.gitignore: -------------------------------------------------------------------------------- 1 | obj 2 | bin 3 | deploy 4 | deploy/* 5 | _ReSharper.* 6 | *.csproj.user 7 | *.resharper.user 8 | *.ReSharper.user 9 | *.resharper 10 | *.suo 11 | *.cache 12 | ~$* 13 | *.ReSharper.user 14 | *.sln.docstates 15 | *.user 16 | /nuget/lib/net40/EmbeddedResourceVirtualPathProvider.dll 17 | /nuget/lib/net40/EmbeddedResourceVirtualPathProvider.pdb 18 | -------------------------------------------------------------------------------- /.vs/config/applicationhost.config: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 22 | 23 | 50 | 51 | 52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | 61 | 62 | 63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | 82 |
83 |
84 | 85 |
86 |
87 |
88 |
89 |
90 |
91 | 92 |
93 |
94 |
95 |
96 |
97 | 98 |
99 |
100 |
101 | 102 |
103 |
104 | 105 |
106 |
107 | 108 |
109 |
110 |
111 | 112 | 113 |
114 |
115 |
116 |
117 |
118 |
119 | 120 |
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 | 947 | 948 | 949 | 950 | 951 | 952 | 953 | 954 | 955 | 956 | 957 | 958 | 959 | 960 | 961 | 962 | 963 | 964 | 965 | 966 | 967 | 968 | 969 | 970 | 971 | 972 | 973 | 974 | 975 | 976 | 977 | 978 | 979 | 980 | 981 | 982 | 983 | 984 | 985 | 986 | 987 | 988 | 989 | 990 | 991 | 992 | 993 | 994 | 995 | 996 | 997 | 998 | 999 | 1000 | 1001 | 1002 | 1003 | 1004 | 1005 | 1006 | 1007 | 1008 | 1009 | 1010 | 1011 | 1012 | 1013 | 1014 | 1015 | 1016 | 1017 | 1018 | 1019 | 1020 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | 1028 | 1029 | 1030 | 1031 | 1032 | 1033 | 1034 | 1035 | 1036 | 1037 | 1038 | 1039 | 1040 | 1041 | 1042 | 1043 | 1044 | 1045 | 1046 | 1047 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "EmbeddedResourceVirtualPathProvider", "EmbeddedResourceVirtualPathProvider\EmbeddedResourceVirtualPathProvider.csproj", "{6298C7D0-B42C-4014-B5DF-E2A871832A3F}" 5 | EndProject 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestWebProject", "TestWebProject\TestWebProject.csproj", "{9A0094B7-E767-48FA-84F1-9CD2DD73CEC3}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestResourceLibrary", "TestResourceLibrary\TestResourceLibrary.csproj", "{F220C6EC-A85F-41C4-BA6E-C92921DE318F}" 9 | EndProject 10 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NugetTestWebProject", "NugetTestWebProject\NugetTestWebProject.csproj", "{03165E98-56F6-48B5-9D13-0CDB5FA69B26}" 11 | EndProject 12 | Global 13 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 14 | Debug|Any CPU = Debug|Any CPU 15 | Release|Any CPU = Release|Any CPU 16 | EndGlobalSection 17 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 18 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {9A0094B7-E767-48FA-84F1-9CD2DD73CEC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 23 | {9A0094B7-E767-48FA-84F1-9CD2DD73CEC3}.Debug|Any CPU.Build.0 = Debug|Any CPU 24 | {9A0094B7-E767-48FA-84F1-9CD2DD73CEC3}.Release|Any CPU.ActiveCfg = Release|Any CPU 25 | {9A0094B7-E767-48FA-84F1-9CD2DD73CEC3}.Release|Any CPU.Build.0 = Release|Any CPU 26 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 27 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F}.Debug|Any CPU.Build.0 = Debug|Any CPU 28 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F}.Release|Any CPU.ActiveCfg = Release|Any CPU 29 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F}.Release|Any CPU.Build.0 = Release|Any CPU 30 | {03165E98-56F6-48B5-9D13-0CDB5FA69B26}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 31 | {03165E98-56F6-48B5-9D13-0CDB5FA69B26}.Debug|Any CPU.Build.0 = Debug|Any CPU 32 | {03165E98-56F6-48B5-9D13-0CDB5FA69B26}.Release|Any CPU.ActiveCfg = Release|Any CPU 33 | {03165E98-56F6-48B5-9D13-0CDB5FA69B26}.Release|Any CPU.Build.0 = Release|Any CPU 34 | EndGlobalSection 35 | GlobalSection(SolutionProperties) = preSolution 36 | HideSolutionNode = FALSE 37 | EndGlobalSection 38 | EndGlobal 39 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.user -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Linq; 4 | using System.Reflection; 5 | using System.Web; 6 | using System.Web.Caching; 7 | 8 | namespace EmbeddedResourceVirtualPathProvider 9 | { 10 | public class EmbeddedResource 11 | { 12 | public EmbeddedResource(Assembly assembly, string resourcePath, string projectSourcePath) 13 | { 14 | this.AssemblyName = assembly.GetName().Name; 15 | System.IO.FileInfo fileInfo = new System.IO.FileInfo(assembly.Location); 16 | AssemblyLastModified = fileInfo.LastWriteTime; 17 | this.ResourcePath = resourcePath; 18 | if (!string.IsNullOrWhiteSpace(projectSourcePath)) 19 | { 20 | Filename = GetFileNameFromProjectSourceDirectory(assembly, resourcePath, projectSourcePath); 21 | 22 | if (Filename != null) //means that the source file was found, or a copy was in the web apps folders 23 | { 24 | GetCacheDependency = (utcStart) => new CacheDependency(Filename, utcStart); 25 | GetStream = () => File.OpenRead(Filename); 26 | return; 27 | } 28 | } 29 | GetCacheDependency = (utcStart) => new CacheDependency(assembly.Location); 30 | GetStream = () => assembly.GetManifestResourceStream(resourcePath); 31 | } 32 | 33 | public string Filename { get; private set; } 34 | 35 | public DateTime AssemblyLastModified { get; private set; } 36 | 37 | public string ResourcePath { get; private set; } 38 | 39 | public Func GetStream { get; private set; } 40 | public Func GetCacheDependency { get; private set; } 41 | 42 | public string AssemblyName { get; private set; } 43 | 44 | string GetFileNameFromProjectSourceDirectory(Assembly assembly, string resourcePath, string projectSourcePath) 45 | { 46 | try 47 | { 48 | if (!Path.IsPathRooted(projectSourcePath)) 49 | { 50 | projectSourcePath = 51 | new DirectoryInfo((Path.Combine(HttpRuntime.AppDomainAppPath, projectSourcePath))).FullName; 52 | } 53 | var fileName = Path.Combine(projectSourcePath, 54 | resourcePath.Substring(assembly.GetName().Name.Length + 1).Replace('.', '\\')); 55 | 56 | 57 | return GetFileName(fileName); 58 | } 59 | catch (Exception ex) 60 | { 61 | #if DEBUG 62 | throw; 63 | #else 64 | Logger.LogWarning("Error reading source files", ex); 65 | return null; 66 | #endif 67 | } 68 | } 69 | 70 | string GetFileName(string possibleFileName) 71 | { 72 | var indexOfLastSlash = possibleFileName.LastIndexOf('\\'); 73 | while (indexOfLastSlash > -1) 74 | { 75 | if (File.Exists(possibleFileName)) return possibleFileName; 76 | possibleFileName = ReplaceChar(possibleFileName, indexOfLastSlash, '.'); 77 | indexOfLastSlash = possibleFileName.LastIndexOf('\\'); 78 | } 79 | return null; 80 | } 81 | 82 | 83 | string ReplaceChar(string text, int index, char charToUse) 84 | { 85 | char[] buffer = text.ToCharArray(); 86 | buffer[index] = charToUse; 87 | return new string(buffer); 88 | } 89 | } 90 | } -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResourceCacheControl.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Web; 6 | 7 | namespace EmbeddedResourceVirtualPathProvider 8 | { 9 | public class EmbeddedResourceCacheControl 10 | { 11 | public int MaxAge; 12 | public HttpCacheability Cacheability; 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResourcePath.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace EmbeddedResourceVirtualPathProvider 7 | { 8 | public class EmbeddedResourcePath 9 | { 10 | public string Directory { get; set; } 11 | 12 | public string Filename { get; set; } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResourceVirtualDirectory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Web.Hosting; 7 | 8 | namespace EmbeddedResourceVirtualPathProvider 9 | { 10 | class EmbeddedResourceVirtualDirectory : VirtualDirectory 11 | { 12 | Dictionary> _resources; 13 | Func _cacheControl; 14 | 15 | public EmbeddedResourceVirtualDirectory(string virtualPath, Dictionary> resources, Func cacheControl) : base(virtualPath) 16 | { 17 | _resources = resources; 18 | _cacheControl = cacheControl; 19 | } 20 | 21 | public override IEnumerable Children 22 | { 23 | get 24 | { 25 | return Files; 26 | } 27 | } 28 | 29 | public override IEnumerable Directories 30 | { 31 | get 32 | { 33 | return new List(); 34 | } 35 | } 36 | 37 | public override IEnumerable Files 38 | { 39 | get 40 | { 41 | return _resources.Select(resource => new EmbeddedResourceVirtualFile(System.IO.Path.Combine(this.VirtualPath, resource.Key), resource.Value.FirstOrDefault(), _cacheControl(resource.Value.FirstOrDefault()))); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResourceVirtualFile.cs: -------------------------------------------------------------------------------- 1 | using System.IO; 2 | using System.Web; 3 | using System.Web.Hosting; 4 | 5 | namespace EmbeddedResourceVirtualPathProvider 6 | { 7 | class EmbeddedResourceVirtualFile : VirtualFile 8 | { 9 | readonly EmbeddedResource embedded; 10 | readonly EmbeddedResourceCacheControl cacheControl; 11 | 12 | public EmbeddedResourceVirtualFile(string virtualPath, EmbeddedResource embedded, EmbeddedResourceCacheControl cacheControl) 13 | : base(virtualPath) 14 | { 15 | this.embedded = embedded; 16 | this.cacheControl = cacheControl; 17 | } 18 | 19 | public override Stream Open() 20 | { 21 | if (cacheControl != null) 22 | { 23 | HttpContext.Current.Response.Cache.SetCacheability(cacheControl.Cacheability); 24 | HttpContext.Current.Response.Cache.AppendCacheExtension("max-age=" + cacheControl.MaxAge); 25 | } 26 | return embedded.GetStream(); 27 | } 28 | 29 | } 30 | } -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/EmbeddedResourceVirtualPathProvider.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F} 9 | Library 10 | Properties 11 | EmbeddedResourceVirtualPathProvider 12 | EmbeddedResourceVirtualPathProvider 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | del ..\..\..\nuget\EmbeddedResourceVirtualPathProvider.Core\lib\net40\*.* /F 59 | copy $(ProjectName).* ..\..\..\nuget\EmbeddedResourceVirtualPathProvider.Core\lib\net40\*.* /Y 60 | 61 | 68 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/Logger.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace EmbeddedResourceVirtualPathProvider 7 | { 8 | public static class Logger 9 | { 10 | static Logger() 11 | { 12 | LogWarning = (message, ex) => { }; 13 | } 14 | 15 | public static Action LogWarning { get; set; } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("EmbeddedResourceVirtualPathProvider")] 9 | [assembly: AssemblyDescription("Enables ASP to read content files (e.g. .css, .js, .aspx) stored as embedded resources in referenced assemblies")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Harry McIntyre")] 12 | [assembly: AssemblyProduct("EmbeddedResourceVirtualPathProvider")] 13 | [assembly: AssemblyCopyright("Copyright © Harry McIntyre 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("0af3a3b6-bda6-4001-9e35-0b47ee2b5fe9")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.*")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/Vpp.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using System.Reflection; 5 | using System.Web; 6 | using System.Web.Caching; 7 | using System.Web.Hosting; 8 | using System.Linq; 9 | using System.Text.RegularExpressions; 10 | 11 | namespace EmbeddedResourceVirtualPathProvider 12 | { 13 | public class Vpp : VirtualPathProvider, IEnumerable 14 | { 15 | readonly Dictionary>> resources = new Dictionary>>(); 16 | 17 | Regex pathPattern = new Regex(@"^(?.*?)?\.(?[^.]*([\.-](?[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5})(\.min)?)?\.[^.]*)$", RegexOptions.Compiled | RegexOptions.IgnoreCase); 18 | 19 | public Vpp(params Assembly[] assemblies) 20 | { 21 | UseResource = er => true; 22 | UseLocalIfAvailable = resource => true; 23 | CacheControl = er => null; 24 | GetPath = resourcePath => DefaultPathFunction(resourcePath); 25 | 26 | Array.ForEach(assemblies, a => Add(a)); 27 | } 28 | 29 | public Func UseResource { get; set; } 30 | public Func UseLocalIfAvailable { get; set; } 31 | public Func CacheControl { get; set; } 32 | public Func GetPath { get; set; } 33 | 34 | public Dictionary>> Resources { get { return resources; } } 35 | 36 | private EmbeddedResourcePath DefaultPathFunction(string resourcePath) 37 | { 38 | Match match = pathPattern.Match(resourcePath); 39 | if (match.Success) 40 | { 41 | return new EmbeddedResourcePath() 42 | { 43 | Directory = match.Groups["directory"].Value, 44 | Filename = match.Groups["filename"].Value 45 | }; 46 | } 47 | 48 | return null; 49 | } 50 | 51 | public void Add(Assembly assembly, string projectSourcePath = null) 52 | { 53 | var assemblyName = assembly.GetName().Name; 54 | 55 | foreach (var resourcePath in assembly.GetManifestResourceNames().Where(r => r.StartsWith(assemblyName))) 56 | { 57 | EmbeddedResourcePath path = GetPath(resourcePath.Substring(assemblyName.Length + 1)); 58 | if (path != null) 59 | { 60 | Dictionary> directoryResources; 61 | string directoryName = path.Directory.ToUpperInvariant(); 62 | string filename = path.Filename.ToUpperInvariant(); 63 | 64 | if (!resources.TryGetValue(directoryName, out directoryResources)) 65 | { 66 | directoryResources = new Dictionary>(); 67 | resources.Add(directoryName, directoryResources); 68 | } 69 | 70 | if (!directoryResources.ContainsKey(filename)) 71 | { 72 | directoryResources[filename] = new List(); 73 | } 74 | directoryResources[filename].Insert(0, new EmbeddedResource(assembly, resourcePath, projectSourcePath)); 75 | } 76 | } 77 | } 78 | 79 | public override bool FileExists(string virtualPath) 80 | { 81 | return (base.FileExists(virtualPath) || GetResourceFromVirtualPath(virtualPath) != null); 82 | } 83 | 84 | public override VirtualDirectory GetDirectory(string virtualDir) 85 | { 86 | string key = virtualDir.Replace('/', '.').TrimStart('~', '.').TrimEnd('.').ToUpperInvariant(); 87 | 88 | Dictionary> directoryResources; 89 | 90 | if (resources.TryGetValue(key, out directoryResources)) 91 | { 92 | return new EmbeddedResourceVirtualDirectory(virtualDir, directoryResources, CacheControl); 93 | } 94 | 95 | return base.GetDirectory(virtualDir); 96 | } 97 | 98 | public override bool DirectoryExists(string virtualDir) 99 | { 100 | string key = virtualDir.Replace('/', '.').TrimStart('~', '.').TrimEnd('.').ToUpperInvariant(); 101 | if (resources.ContainsKey(key)) 102 | { 103 | return true; 104 | } 105 | 106 | return base.DirectoryExists(virtualDir); 107 | } 108 | 109 | public override VirtualFile GetFile(string virtualPath) 110 | { 111 | //if (base.FileExists(virtualPath)) return base.GetFile(virtualPath); 112 | var resource = GetResourceFromVirtualPath(virtualPath); 113 | if (resource != null) 114 | return new EmbeddedResourceVirtualFile(virtualPath, resource, CacheControl(resource)); 115 | return base.GetFile(virtualPath); 116 | } 117 | 118 | public override string CombineVirtualPaths(string basePath, string relativePath) 119 | { 120 | var combineVirtualPaths = base.CombineVirtualPaths(basePath, relativePath); 121 | return combineVirtualPaths; 122 | } 123 | 124 | public override string GetFileHash(string virtualPath, IEnumerable virtualPathDependencies) 125 | { 126 | var fileHash = base.GetFileHash(virtualPath, virtualPathDependencies); 127 | return fileHash; 128 | } 129 | 130 | public override string GetCacheKey(string virtualPath) 131 | { 132 | var resource = GetResourceFromVirtualPath(virtualPath); 133 | if (resource != null) 134 | { 135 | return (virtualPath + resource.AssemblyName + resource.AssemblyLastModified.Ticks).GetHashCode().ToString(); 136 | } 137 | return base.GetCacheKey(virtualPath); 138 | } 139 | 140 | public bool IsInt(string c) 141 | { 142 | int outChar; 143 | return int.TryParse(c, out outChar); 144 | } 145 | 146 | public EmbeddedResource GetResourceFromVirtualPath(string virtualPath) 147 | { 148 | var path = VirtualPathUtility.ToAppRelative(virtualPath).TrimStart('~', '/'); 149 | var index = path.LastIndexOf("/"); 150 | if (index != -1) 151 | { 152 | var folder = path.Substring(0, index); //embedded resources with "-"in their folder names are stored as "_". 153 | var folderItems = folder.Split('/'); 154 | List result = new List(); 155 | foreach (var item in folderItems) 156 | { 157 | var resultFolder = item; 158 | resultFolder = resultFolder.Replace("-", "_"); //replace - with underscore 159 | 160 | var outputFolder = ""; 161 | var outs = ""; 162 | for (var i = 0; i < resultFolder.Length; i++) 163 | { 164 | if (i == 0 && IsInt(resultFolder[i].ToString())) //if the first character is a int, then prefix 165 | outs += "_"; 166 | 167 | outs += resultFolder[i]; 168 | 169 | //if any character follows a dot with a int, prefix with an underscore 170 | if (resultFolder[i] == '.') 171 | { 172 | //get the next one 173 | if (IsInt(resultFolder.Substring(i + 1, 1))) 174 | outs += "_"; 175 | } 176 | } 177 | resultFolder = outs; 178 | result.Add(resultFolder); 179 | } 180 | folder = string.Join(".", result); 181 | 182 | path = folder + path.Substring(index); 183 | } 184 | 185 | Match pathMatch = pathPattern.Match(path.Replace('/', '.').ToUpperInvariant()); 186 | if (pathMatch.Success) 187 | { 188 | string directory = pathMatch.Groups["directory"].Value; 189 | string filename = pathMatch.Groups["filename"].Value; 190 | 191 | if (resources.ContainsKey(directory)) 192 | { 193 | var directoryResources = resources[directory]; 194 | if (directoryResources.ContainsKey(filename)) 195 | { 196 | var resource = directoryResources[filename].FirstOrDefault(UseResource); 197 | if (resource != null && !ShouldUsePrevious(virtualPath, resource)) 198 | { 199 | return resource; 200 | } 201 | } 202 | } 203 | } 204 | return null; 205 | } 206 | 207 | public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart) 208 | { 209 | var resource = GetResourceFromVirtualPath(virtualPath); 210 | if (resource != null) 211 | { 212 | return resource.GetCacheDependency(utcStart); 213 | } 214 | 215 | var embeddedResourceDependencies = virtualPathDependencies.OfType() 216 | .Select(x => new { path = x, resource = GetResourceFromVirtualPath(x) }) 217 | .Where(x => x.resource != null) 218 | .ToList(); 219 | 220 | if (embeddedResourceDependencies.Any()) 221 | { 222 | virtualPathDependencies = virtualPathDependencies.OfType() 223 | .Except(embeddedResourceDependencies.Select(v => v.path)) 224 | .Concat(embeddedResourceDependencies.Select(v => $"/bin/{v.resource.AssemblyName}").Distinct()); 225 | } 226 | 227 | if (DirectoryExists(virtualPath) || FileExists(virtualPath)) 228 | { 229 | return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart); 230 | } 231 | 232 | return null; 233 | } 234 | 235 | private bool ShouldUsePrevious(string virtualPath, EmbeddedResource resource) 236 | { 237 | return base.FileExists(virtualPath) && UseLocalIfAvailable(resource); 238 | } 239 | 240 | 241 | //public override string GetCacheKey(string virtualPath) 242 | //{ 243 | // var resource = GetResourceFromVirtualPath(virtualPath); 244 | // if (resource != null) return virtualPath + "blah"; 245 | // return base.GetCacheKey(virtualPath); 246 | //} 247 | 248 | public IEnumerator GetEnumerator() 249 | { 250 | throw new NotImplementedException("Only got this so that we can use object collection initializer syntax"); 251 | } 252 | } 253 | } -------------------------------------------------------------------------------- /EmbeddedResourceVirtualPathProvider/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Harry McIntyre 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of 6 | this software and associated documentation files (the "Software"), to deal in 7 | the Software without restriction, including without limitation the rights to 8 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 9 | the Software, and to permit persons to whom the Software is furnished to do so, 10 | subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 17 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 18 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 19 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 20 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /NugetTestWebProject/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | *.user -------------------------------------------------------------------------------- /NugetTestWebProject/App_Start/EmbeddedResourceVirtualPathProviderStart.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Linq; 3 | 4 | [assembly: WebActivatorEx.PostApplicationStartMethod(typeof(NugetTestWebProject.EmbeddedResourceVirtualPathProviderStart), "Start")] 5 | 6 | namespace NugetTestWebProject 7 | { 8 | public static class EmbeddedResourceVirtualPathProviderStart 9 | { 10 | public static void Start() 11 | { 12 | //By default, we scan all non system assemblies for embedded resources 13 | var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies() 14 | .Cast() 15 | .Where(a => a.GetName().Name.StartsWith("System") == false); 16 | System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceVirtualPathProvider.Vpp(assemblies.ToArray()) 17 | { 18 | //you can do a specific assembly registration too. If you provide the assemly source path, it can read 19 | //from the source file so you can change the content while the app is running without needing to rebuild 20 | //{typeof(SomeAssembly.SomeClass).Assembly, @"..\SomeAssembly"} 21 | }); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /NugetTestWebProject/Default.aspx: -------------------------------------------------------------------------------- 1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="NugetTestWebProject.WebForm1" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 | This page loads scripts from a referenced assembly 17 |
18 |
19 | 20 | 21 | -------------------------------------------------------------------------------- /NugetTestWebProject/Default.aspx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace NugetTestWebProject 4 | { 5 | public partial class WebForm1 : System.Web.UI.Page 6 | { 7 | protected void Page_Load(object sender, EventArgs e) 8 | { 9 | 10 | } 11 | } 12 | } -------------------------------------------------------------------------------- /NugetTestWebProject/Default.aspx.designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace NugetTestWebProject 11 | { 12 | 13 | 14 | public partial class WebForm1 15 | { 16 | 17 | /// 18 | /// form1 control. 19 | /// 20 | /// 21 | /// Auto-generated field. 22 | /// To modify move field declaration from designer file to code-behind file. 23 | /// 24 | protected global::System.Web.UI.HtmlControls.HtmlForm form1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /NugetTestWebProject/NugetTestWebProject.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {03165E98-56F6-48B5-9D13-0CDB5FA69B26} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | NugetTestWebProject 15 | NugetTestWebProject 16 | v4.0 17 | true 18 | 19 | 20 | 4.0 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | ..\packages\EmbeddedResourceVirtualPathProvider.1.3.26\lib\net40\EmbeddedResourceVirtualPathProvider.dll 43 | True 44 | 45 | 46 | 47 | ..\packages\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll 48 | True 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | ..\packages\WebActivatorEx.2.0.3\lib\net40\WebActivatorEx.dll 67 | True 68 | 69 | 70 | 71 | 72 | 73 | 74 | Designer 75 | 76 | 77 | Web.config 78 | 79 | 80 | Web.config 81 | 82 | 83 | 84 | 85 | 86 | Default.aspx 87 | ASPXCodeBehind 88 | 89 | 90 | Default.aspx 91 | 92 | 93 | 94 | 95 | 96 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F} 97 | TestResourceLibrary 98 | 99 | 100 | 101 | 102 | 103 | 104 | 10.0 105 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | True 115 | True 116 | 62200 117 | / 118 | http://localhost:62200/ 119 | False 120 | False 121 | 122 | 123 | False 124 | 125 | 126 | 127 | 128 | 135 | -------------------------------------------------------------------------------- /NugetTestWebProject/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("NugetTestWebProject")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("NugetTestWebProject")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("a2fd5a00-8b01-413a-8e08-dbb7cbba3293")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /NugetTestWebProject/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /NugetTestWebProject/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /NugetTestWebProject/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /NugetTestWebProject/alert2.js: -------------------------------------------------------------------------------- 1 | alert("alert2.js from TestWebProject - overrides the referenced assembly") -------------------------------------------------------------------------------- /NugetTestWebProject/packages.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | # EmbeddedResourceVirtualPathProvider # 2 | 3 | A custom VirtualPathProvider for IIS - load views and assets from Embedded Resources in referenced assemblies . To get started, install into your ASP.NET web application via nuget: 4 | 5 | > Install-Package EmbeddedResourceVirtualPathProvider 6 | 7 | This will add some code into `App_Start` registering the provider. 8 | 9 | Move views and assets into other assemblies, maintaining folder structure. e.g. 10 | 11 | `/MyAspNetApp/Views/Thing/Thing.cshtml -> /ThingComponent/Views/Thing/Thing.cshtml` 12 | 13 | And set the the files BuildAction as EmbbeddedResource. Make sure your assembly is referenced, and you're done! 14 | 15 | By default, all assemblies in the appdomain are scanned. You can restrict this in `App_Start\EmbeddedResourceVirtualPathProviderStart.cs` file. You can also map assemblies to their location on disk, so they ca nbe refereshed when you edit the files during development. 16 | 17 | There is some help at https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider/wiki/Help 18 | 19 | 20 | ## Install Actions 21 | On installing the package we'll get: 22 | 23 | * `App_Start/EmbeddedResourceVirtualPathProviderStart.cs` file created - it contains provider registration via WebActivator 24 | * section `system.webServer`/`handlers` in web.config will be updated with: 25 | 26 | ``` 27 | 28 | 29 | 30 | 31 | ``` 32 | 33 | * WebActivatorEx package will be installed 34 | 35 | If you don't want all these side effects then use package `EmbeddedResourceVirtualPathProvider.Core` which contains only an assembly. 36 | 37 | 38 | ## Dynamic Content Routing ## 39 | 40 | You can set up rules determining the order to check assemblies for resources, letting you (for example) have different view assemblies for different hostnames. 41 | 42 | Please check out my other projects! 43 | 44 | Cheers, Harry 45 | 46 | @mcintyre321 47 | 48 | MIT Licenced 49 | 50 | 51 | 52 | 53 | [![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/mcintyre321/embeddedresourcevirtualpathprovider/trend.png)](https://bitdeli.com/free "Bitdeli Badge") 54 | 55 | -------------------------------------------------------------------------------- /TestResourceLibrary/3rd3Party/3select2-3.4.5/select2.js: -------------------------------------------------------------------------------- 1 | alert("3rd3Party/3select2-3.4.5/select2.js - works with more complex path") -------------------------------------------------------------------------------- /TestResourceLibrary/3rd3Party/hammer.js-1.0.10/hammer.js: -------------------------------------------------------------------------------- 1 | alert("3rd3Party/hammer.js-1.0.10/hammer.js - works with more complex path") -------------------------------------------------------------------------------- /TestResourceLibrary/Marker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | 6 | namespace TestResourceLibrary 7 | { 8 | public class Marker 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /TestResourceLibrary/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TestResourceLibrary")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("TestResourceLibrary")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("fd2f201b-9dba-4048-8869-ef2342a2d846")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.0")] 36 | [assembly: AssemblyFileVersion("1.0.0.0")] 37 | -------------------------------------------------------------------------------- /TestResourceLibrary/Scripts/alert-1.12.34567.min.js: -------------------------------------------------------------------------------- 1 | alert("Scripts/alert-1.12.34567.min.js - works with more complex path") -------------------------------------------------------------------------------- /TestResourceLibrary/TestResourceLibrary.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | AnyCPU 6 | 8.0.30703 7 | 2.0 8 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F} 9 | Library 10 | Properties 11 | TestResourceLibrary 12 | TestResourceLibrary 13 | v4.0 14 | 512 15 | 16 | 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | 25 | 26 | pdbonly 27 | true 28 | bin\Release\ 29 | TRACE 30 | prompt 31 | 4 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 69 | -------------------------------------------------------------------------------- /TestResourceLibrary/alert.js: -------------------------------------------------------------------------------- 1 | alert("alert.js (loaded from referenced assembly)") -------------------------------------------------------------------------------- /TestResourceLibrary/alert2.js: -------------------------------------------------------------------------------- 1 | alert("alert2.js") -------------------------------------------------------------------------------- /TestWebProject/App_Start/EmbeddedResourceVirtualPathProviderStart.cs: -------------------------------------------------------------------------------- 1 | using System.Linq; 2 | using System.Reflection; 3 | 4 | //[assembly: WebActivatorEx.PostApplicationStartMethod(typeof(NugetTestWebProject.EmbeddedResourceVirtualPathProviderStart), "Start")] 5 | 6 | namespace TestWebProject 7 | { 8 | public static class EmbeddedResourceVirtualPathProviderStart 9 | { 10 | public static void Start() 11 | { 12 | //By default, we scan all non system assemblies for embedded resources 13 | var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies() 14 | .Cast() 15 | .Where(a => a.GetName().Name.StartsWith("System") == false); 16 | 17 | var vpp = new EmbeddedResourceVirtualPathProvider.Vpp(assemblies.ToArray()); 18 | 19 | System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(vpp); 20 | } 21 | } 22 | } -------------------------------------------------------------------------------- /TestWebProject/Default.aspx: -------------------------------------------------------------------------------- 1 | <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="TestWebProject.WebForm1" %> 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 |
17 | This page loads scripts from a referenced assembly 18 |
19 |
20 | 21 | 22 | -------------------------------------------------------------------------------- /TestWebProject/Default.aspx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.UI; 6 | using System.Web.UI.WebControls; 7 | 8 | namespace TestWebProject 9 | { 10 | public partial class WebForm1 : System.Web.UI.Page 11 | { 12 | protected void Page_Load(object sender, EventArgs e) 13 | { 14 | } 15 | } 16 | } -------------------------------------------------------------------------------- /TestWebProject/Default.aspx.designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // 5 | // Changes to this file may cause incorrect behavior and will be lost if 6 | // the code is regenerated. 7 | // 8 | //------------------------------------------------------------------------------ 9 | 10 | namespace TestWebProject 11 | { 12 | 13 | 14 | public partial class WebForm1 15 | { 16 | 17 | /// 18 | /// form1 control. 19 | /// 20 | /// 21 | /// Auto-generated field. 22 | /// To modify move field declaration from designer file to code-behind file. 23 | /// 24 | protected global::System.Web.UI.HtmlControls.HtmlForm form1; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /TestWebProject/Global.asax: -------------------------------------------------------------------------------- 1 | <%@ Application Codebehind="Global.asax.cs" Inherits="TestWebProject.Global" Language="C#" %> 2 | -------------------------------------------------------------------------------- /TestWebProject/Global.asax.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Web; 5 | using System.Web.Security; 6 | using System.Web.SessionState; 7 | 8 | namespace TestWebProject 9 | { 10 | public class Global : System.Web.HttpApplication 11 | { 12 | 13 | protected void Application_Start(object sender, EventArgs e) 14 | { 15 | EmbeddedResourceVirtualPathProviderStart.Start(); 16 | } 17 | 18 | protected void Session_Start(object sender, EventArgs e) 19 | { 20 | 21 | } 22 | 23 | protected void Application_BeginRequest(object sender, EventArgs e) 24 | { 25 | } 26 | 27 | protected void Application_AuthenticateRequest(object sender, EventArgs e) 28 | { 29 | 30 | } 31 | 32 | protected void Application_Error(object sender, EventArgs e) 33 | { 34 | 35 | } 36 | 37 | protected void Session_End(object sender, EventArgs e) 38 | { 39 | 40 | } 41 | 42 | protected void Application_End(object sender, EventArgs e) 43 | { 44 | 45 | } 46 | } 47 | } -------------------------------------------------------------------------------- /TestWebProject/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TestWebProject")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Microsoft")] 12 | [assembly: AssemblyProduct("TestWebProject")] 13 | [assembly: AssemblyCopyright("Copyright © Microsoft 2011")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("1741b638-0a80-4bcd-9839-1113958bdc30")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Revision and Build Numbers 33 | // by using the '*' as shown below: 34 | [assembly: AssemblyVersion("1.0.0.0")] 35 | [assembly: AssemblyFileVersion("1.0.0.0")] 36 | -------------------------------------------------------------------------------- /TestWebProject/TestWebProject.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | 8 | 9 | 2.0 10 | {9A0094B7-E767-48FA-84F1-9CD2DD73CEC3} 11 | {349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc} 12 | Library 13 | Properties 14 | TestWebProject 15 | TestWebProject 16 | v4.0 17 | true 18 | 19 | 20 | 4.0 21 | 22 | 23 | 24 | true 25 | full 26 | false 27 | bin\ 28 | DEBUG;TRACE 29 | prompt 30 | 4 31 | 32 | 33 | pdbonly 34 | true 35 | bin\ 36 | TRACE 37 | prompt 38 | 4 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | Global.asax 67 | 68 | 69 | 70 | Default.aspx 71 | ASPXCodeBehind 72 | 73 | 74 | Default.aspx 75 | 76 | 77 | 78 | 79 | {6298C7D0-B42C-4014-B5DF-E2A871832A3F} 80 | EmbeddedResourceVirtualPathProvider 81 | 82 | 83 | {F220C6EC-A85F-41C4-BA6E-C92921DE318F} 84 | TestResourceLibrary 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | web.config 93 | 94 | 95 | 96 | 97 | web.config 98 | 99 | 100 | 101 | 10.0 102 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | True 112 | True 113 | 56338 114 | / 115 | http://localhost:56338/ 116 | False 117 | False 118 | 119 | 120 | False 121 | 122 | 123 | 124 | 125 | 132 | -------------------------------------------------------------------------------- /TestWebProject/Web.Debug.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 29 | 30 | -------------------------------------------------------------------------------- /TestWebProject/Web.Release.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 17 | 18 | 19 | 30 | 31 | -------------------------------------------------------------------------------- /TestWebProject/Web.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /TestWebProject/alert2.js: -------------------------------------------------------------------------------- 1 | alert("alert2.js from TestWebProject - overrides the referenced assembly") -------------------------------------------------------------------------------- /nuget/EmbeddedResourceVirtualPathProvider.Core/EmbeddedResourceVirtualPathProvider.Core.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EmbeddedResourceVirtualPathProvider.Core 5 | $version$ 6 | Harry McIntyre 7 | Harry McIntyre 8 | https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider 9 | false 10 | Enables ASP to read content files (e.g. .css, .js, .aspx) stored as embedded resources in referenced assemblies. This core package contains only an assembly, see also EmbeddedResourceVirtualPathProvider with bootstrap code for seamless integration into your app. 11 | asp.net portable embedded resources virtualpathprovider 12 | 13 | 14 | -------------------------------------------------------------------------------- /nuget/EmbeddedResourceVirtualPathProvider.Core/lib/net40/placeholder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/nuget/EmbeddedResourceVirtualPathProvider.Core/lib/net40/placeholder.txt -------------------------------------------------------------------------------- /nuget/EmbeddedResourceVirtualPathProvider/EmbeddedResourceVirtualPathProvider.nuspec: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | EmbeddedResourceVirtualPathProvider 5 | $version$ 6 | Harry McIntyre 7 | Harry McIntyre 8 | https://github.com/mcintyre321/EmbeddedResourceVirtualPathProvider 9 | false 10 | Enables ASP to read content files (e.g. .css, .js, .aspx) stored as embedded resources in referenced assemblies. This full package contrains additional bootstrap template code and settings for seamless integration into apps. 11 | asp.net portable embedded resources virtualpathprovider 12 | 13 | 14 | 15 | 16 | 17 | 18 | -------------------------------------------------------------------------------- /nuget/EmbeddedResourceVirtualPathProvider/content/App_Start/EmbeddedResourceVirtualPathProviderStart.cs.pp: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Linq; 3 | 4 | [assembly: WebActivatorEx.PostApplicationStartMethod(typeof($rootnamespace$.EmbeddedResourceVirtualPathProviderStart), "Start")] 5 | 6 | namespace $rootnamespace$ 7 | { 8 | public static class EmbeddedResourceVirtualPathProviderStart 9 | { 10 | public static void Start() 11 | { 12 | //By default, we scan all non system assemblies for embedded resources 13 | var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies() 14 | .Cast() 15 | .Where(a => a.GetName().Name.StartsWith("System") == false); 16 | System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceVirtualPathProvider.Vpp(assemblies.ToArray()) 17 | { 18 | //you can do a specific assembly registration too. If you provide the assemly source path, it can read 19 | //from the source file so you can change the content while the app is running without needing to rebuild 20 | //{typeof(SomeAssembly.SomeClass).Assembly, @"..\SomeAssembly"} 21 | }); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /nuget/EmbeddedResourceVirtualPathProvider/content/web.config.transform: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/EmbeddedResourceVirtualPathProvider.1.3.26.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/EmbeddedResourceVirtualPathProvider.1.3.26/EmbeddedResourceVirtualPathProvider.1.3.26.nupkg -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/content/App_Start/EmbeddedResourceVirtualPathProviderStart.cs.pp: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Linq; 3 | 4 | [assembly: WebActivatorEx.PostApplicationStartMethod(typeof($rootnamespace$.EmbeddedResourceVirtualPathProviderStart), "Start")] 5 | 6 | namespace $rootnamespace$ 7 | { 8 | public static class EmbeddedResourceVirtualPathProviderStart 9 | { 10 | public static void Start() 11 | { 12 | //By default, we scan all non system assemblies for embedded resources 13 | var assemblies = System.Web.Compilation.BuildManager.GetReferencedAssemblies() 14 | .Cast() 15 | .Where(a => a.GetName().Name.StartsWith("System") == false); 16 | System.Web.Hosting.HostingEnvironment.RegisterVirtualPathProvider(new EmbeddedResourceVirtualPathProvider.Vpp(assemblies.ToArray()) 17 | { 18 | //you can do a specific assembly registration too. If you provide the assemly source path, it can read 19 | //from the source file so you can change the content while the app is running without needing to rebuild 20 | //{typeof(SomeAssembly.SomeClass).Assembly, @"..\SomeAssembly"} 21 | }); 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/content/web.config.transform: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/EmbeddedResourceVirtualPathProvider.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/EmbeddedResourceVirtualPathProvider.dll -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/EmbeddedResourceVirtualPathProvider.pdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/EmbeddedResourceVirtualPathProvider.pdb -------------------------------------------------------------------------------- /packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/placeholder.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/EmbeddedResourceVirtualPathProvider.1.3.26/lib/net40/placeholder.txt -------------------------------------------------------------------------------- /packages/Microsoft.Web.Infrastructure.1.0.0.0/Microsoft.Web.Infrastructure.1.0.0.0.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/Microsoft.Web.Infrastructure.1.0.0.0/Microsoft.Web.Infrastructure.1.0.0.0.nupkg -------------------------------------------------------------------------------- /packages/Microsoft.Web.Infrastructure.1.0.0.0/lib/net40/Microsoft.Web.Infrastructure.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/Microsoft.Web.Infrastructure.1.0.0.0/lib/net40/Microsoft.Web.Infrastructure.dll -------------------------------------------------------------------------------- /packages/WebActivator.1.4.1/WebActivator.1.4.1.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/WebActivator.1.4.1/WebActivator.1.4.1.nupkg -------------------------------------------------------------------------------- /packages/WebActivator.1.4.1/lib/net40/WebActivator.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/WebActivator.1.4.1/lib/net40/WebActivator.dll -------------------------------------------------------------------------------- /packages/WebActivatorEx.2.0.3/WebActivatorEx.2.0.3.nupkg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/WebActivatorEx.2.0.3/WebActivatorEx.2.0.3.nupkg -------------------------------------------------------------------------------- /packages/WebActivatorEx.2.0.3/lib/net40/WebActivatorEx.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcintyre321/EmbeddedResourceVirtualPathProvider/2f38cf2bc0e72052e03b4f36483d4ff45809fc45/packages/WebActivatorEx.2.0.3/lib/net40/WebActivatorEx.dll -------------------------------------------------------------------------------- /packages/repositories.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | --------------------------------------------------------------------------------