Skip to content

Commit

Permalink
Fix for "Unable to load bundles" while running using IIS Express (#422)
Browse files Browse the repository at this point in the history
* New constructor with IHostingEnvironment

With the new constructor, bundle provider can access root path for the application. This will help resolve path for bundleconfig.json

* Update BundilProvider to use new constructor

The new constructor will ensure that the path resolved for bundleconfig.json is not based on working directory but based on hostingEnvironment.ContentRootPath
  • Loading branch information
josejamesp authored and madskristensen committed Apr 15, 2019
1 parent 620549a commit bc7f41f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
4 changes: 2 additions & 2 deletions src/BundlerMinifier.TagHelpers/BundleTagHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public BundleTagHelper(IHostingEnvironment hostingEnvironment, IMemoryCache cach
options.Configure(hostingEnvironment);
}

_bundleProvider = bundleProvider ?? new BundleProvider();
_bundleProvider = bundleProvider ?? new BundleProvider(hostingEnvironment);
_options = options;
_hostingEnvironment = hostingEnvironment;
_cache = cache;
Expand Down Expand Up @@ -138,4 +138,4 @@ private string GetSrc(string path)
return null;
}
}
}
}
26 changes: 21 additions & 5 deletions src/BundlerMinifier.TagHelpers/BundlesProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Microsoft.AspNetCore.Hosting;

namespace BundlerMinifier.TagHelpers
{
Expand All @@ -12,16 +13,31 @@ public class BundleProvider : IBundleProvider, IDisposable
private IList<Bundle> _bundles;
private FileSystemWatcher _fileWatcher;

public BundleProvider()
: this("bundleconfig.json")

public BundleProvider() : this(null)
{
}

public BundleProvider(string configurationPath)
public BundleProvider(IHostingEnvironment hostingEnvironment)
: this("bundleconfig.json", hostingEnvironment)
{
}

public BundleProvider(string configurationPath, IHostingEnvironment hostingEnvironment)
{
if (configurationPath == null) throw new ArgumentNullException(nameof(configurationPath));

var fullPath = Path.GetFullPath(configurationPath);
string filePath;
if (hostingEnvironment != null && string.IsNullOrWhiteSpace(Path.GetDirectoryName(configurationPath)))
{
filePath = Path.Combine(hostingEnvironment.ContentRootPath, configurationPath);
}
else
{
filePath = configurationPath;
}

var fullPath = Path.GetFullPath(filePath);
var directory = Path.GetDirectoryName(fullPath);
var fileName = Path.GetFileName(fullPath);
_configurationPath = fullPath;
Expand Down Expand Up @@ -91,4 +107,4 @@ public void Dispose()
}
}
}
}
}

0 comments on commit bc7f41f

Please sign in to comment.