Description
The documentation is out of date as it applies to Core 2.0. And for development environments other than windows, additional steps are likely necessary to get a default aspnet core template up and running using React.NET.
Using Visual Studio for Mac on macOS sierra, I had to do the following to get the tutorial up and running.
(1) Install the following nuget package
Install-Package JavaScriptEngineSwitcher.ChakraCore.Native.osx-x64
(2) Fetch the latest Chakra runtime from github
https://github.com/Microsoft/ChakraCore/releases
and copy that over the old runtime installed by the nuget package
.nuget/packages/javascriptengineswitcher.chakracore.native.osx-x64/2.4.6/runtimes/osx-x64/native/libChakraCore.dylib
(3) add the following using statements to Startup.cs
using JavaScriptEngineSwitcher.Core;
using JavaScriptEngineSwitcher.ChakraCore;
(4) Modify the return type of ConfigureServices
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddReact();
services.AddMvc();
return services.BuildServiceProvider();
}
(5) Switch out the javascript engine in Configure
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Home/Error");
}
var engineSwitcher = JsEngineSwitcher.Instance;
engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;
engineSwitcher.EngineFactories
.AddChakraCore();
app.UseReact(config=>{
});
app.UseStaticFiles();
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
}
Then the tutorial worked as expected. Posting the above might save someone else a number of hours scouring the issue threads.