Skip to content

Making React.AspNet compatible with ASP.NET Core RC2 #271

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 22, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ version: '{build}'
os: Visual Studio 2015
install:
- set PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin;%PATH%
- dnvm update-self
- dnvm install 1.0.0-rc1-update1
build:
project: build.proj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this run the equivalent dotnet command to ensure RC2 is installed on the build machine?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I know it no longer works that way in RC2. There is no equivalent to dnvm in the new toolset. If you have .NET Core RC2 installed already, you can just get the ASP.NET Core packages using NuGet.
That was one of the biggest changes from RC1 to RC2, and it was done in order to make all .NET Core environments consistent with each other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info 👍

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like they've got an install script for CI servers (see https://dotnet.github.io/docs/core-concepts/dnx-migration.html). However, their docs for AppVeyor just say "TODO" (https://dotnet.github.io/docs/core-concepts/core-sdk/cli/using-ci-with-cli.html). It's fine to ignore that for now if the AppVeyor build actually works with no changes.

verbosity: normal
Expand Down
39 changes: 19 additions & 20 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ of patent rights can be found in the PATENTS file in the same directory.
<PackageAssemblies Include="Cassette.React" />
<PackageAssemblies Include="React.MSBuild" />
<PackageAssemblies Include="React.Owin" />
<PackageAssembliesAspNet5 Include="React.AspNet" />
<AspNet5ProjectJson Include="src/React.AspNet/project.json" />
<AspNet5ProjectJson Include="src/React.Sample.Mvc6/project.json" />
<AspNet5ProjectJson Include="src/wrap/**/project.json" />
<PackageAssembliesAspNetCore Include="React.AspNet" />
<AspNetCoreProjectJson Include="src/wrap/**/project.json" />
<AspNetCoreProjectJson Include="src/React.AspNet/project.json" />
<AspNetCoreProjectJson Include="src/React.Sample.Mvc6/project.json" />
</ItemGroup>

<Import Project="src/React.tasks.proj" />
Expand All @@ -42,10 +42,10 @@ of patent rights can be found in the PATENTS file in the same directory.
WorkingDirectory="$(MSBuildProjectDirectory)"
Command="tools\NuGet\nuget.exe restore $(SolutionFile)"
/>
<!-- NuGet packages for ASP.NET 5 projects -->
<!-- NuGet packages for ASP.NET Core projects -->
<Exec
WorkingDirectory="$(MSBuildProjectDirectory)"
Command="dnu restore --quiet --parallel src\React.AspNet src\React.Sample.Mvc6"
Command="dotnet restore --quiet src\React.AspNet src\React.Sample.Mvc6"
/>
<!-- npm packages -->
<Exec
Expand Down Expand Up @@ -81,7 +81,7 @@ of patent rights can be found in the PATENTS file in the same directory.
AssemblyInformationalVersion="$(Major).$(Minor).$(FullBuild)"
/>
<!--
Set version for ASP.NET 5 projects. In theory K_BUILD_VERSION should work but it doesn't seem
Set version for ASP.NET Core projects. In theory K_BUILD_VERSION should work but it doesn't seem
to be functional yet :(. We work around this by physically writing the build number to the
project.json files. For development builds we write the full version number (including
build date) and reset it later so the dev build number isn't commited to the repo.
Expand All @@ -91,18 +91,18 @@ of patent rights can be found in the PATENTS file in the same directory.
Value="$(Build)"
/-->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
Files="@(AspNetCoreProjectJson)"
Version="$(Major).$(Minor).$(FullBuild)"
/>
</Target>

<Target Name="Clean" BeforeTargets="Build">
<!--
ASP.NET 5 projects don't delete generated .nupkg files when cleaned or rebuilt, so we need to
ASP.NET Core projects don't delete generated .nupkg files when cleaned or rebuilt, so we need to
do it here. See https://github.com/aspnet/XRE/issues/1301
-->
<DeleteTree Directories="src/artifacts" />
<DeleteTree Directories="bin/%(PackageAssembliesAspNet5.Identity)/Release" />
<DeleteTree Directories="bin/%(PackageAssembliesAspNetCore.Identity)/Release" />
</Target>

<Target Name="Build" DependsOnTargets="RestorePackages;UpdateVersion">
Expand All @@ -111,10 +111,10 @@ of patent rights can be found in the PATENTS file in the same directory.
<Exec WorkingDirectory="src/React.Sample.Webpack" Command="node_modules/.bin/webpack" />
</Target>

<Target Name="ResetAspNetVersion" AfterTargets="Build">
<!-- Resets the version number in ASP.NET project.json files so we don't commit -dev- version numbers -->
<Target Name="ResetAspNetVersion" AfterTargets="AspNetPackages">
<!-- Resets the version number in ASP.NET Core project.json files so we don't commit -dev- version numbers -->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
Files="@(AspNetCoreProjectJson)"
Version="$(Major).$(Minor).$(Build)-*"
/>
</Target>
Expand Down Expand Up @@ -148,13 +148,12 @@ of patent rights can be found in the PATENTS file in the same directory.
Command="tools\NuGet\nuget.exe pack src/%(PackageAssemblies.Identity)/%(PackageAssemblies.Identity).csproj -IncludeReferencedProjects -Symbols -Prop Configuration=Release -OutputDirectory output"
/>
</Target>

<Target Name="CopyAspNetPackages" AfterTargets="Package">
<!-- Copy over ASP.NET 5 packages -->
<ItemGroup>
<AspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/Release/*.nupkg" />
</ItemGroup>
<Copy SourceFiles="@(AspNet5Packages)" DestinationFolder="$(PackageOutputDir)" />

<Target Name="AspNetPackages" AfterTargets="Package">
<Exec
WorkingDirectory="$(MSBuildProjectDirectory)"
Command="dotnet pack --output $(PackageOutputDir) --build-base-path bin/ --configuration Release --no-build src/%(PackageAssembliesAspNetCore.Identity)/project.json"
/>
</Target>

<Target Name="Push">
Expand Down
2 changes: 1 addition & 1 deletion src/React.AspNet/AspNetFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/

using System.IO;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNetCore.Hosting;

namespace React.AspNet
{
Expand Down
15 changes: 8 additions & 7 deletions src/React.AspNet/BabelFileMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.StaticFiles;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.StaticFiles;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace React.AspNet
{
Expand Down Expand Up @@ -76,19 +77,19 @@ private StaticFileMiddleware CreateFileMiddleware(IBabel babel)
return new StaticFileMiddleware(
_next,
_hostingEnv,
new StaticFileOptions
Options.Create(new StaticFileOptions
{
ContentTypeProvider = _options.StaticFileOptions.ContentTypeProvider,
DefaultContentType = _options.StaticFileOptions.DefaultContentType,
OnPrepareResponse = _options.StaticFileOptions.OnPrepareResponse,
RequestPath = _options.StaticFileOptions.RequestPath,
ServeUnknownFileTypes = _options.StaticFileOptions.ServeUnknownFileTypes,
FileProvider = new BabelFileSystem(
babel,
babel,
_options.StaticFileOptions.FileProvider ?? _hostingEnv.WebRootFileProvider,
_options.Extensions
)
},
}),
_loggerFactory
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/React.AspNet/BabelFileOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#if OWIN
using Microsoft.Owin.StaticFiles;
#else
using Microsoft.AspNet.StaticFiles;
using Microsoft.AspNetCore.Builder;
#endif

#if OWIN
Expand Down
6 changes: 3 additions & 3 deletions src/React.AspNet/BabelFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
using Microsoft.Owin.FileSystems;
using IOwinFileSystem = Microsoft.Owin.FileSystems.IFileSystem;
#else
using Microsoft.AspNet.FileProviders;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Primitives;
using IOwinFileSystem = Microsoft.AspNet.FileProviders.IFileProvider;
using PhysicalFileSystem = Microsoft.AspNet.FileProviders.PhysicalFileProvider;
using IOwinFileSystem = Microsoft.Extensions.FileProviders.IFileProvider;
using PhysicalFileSystem = Microsoft.Extensions.FileProviders.PhysicalFileProvider;
#endif

#if OWIN
Expand Down
4 changes: 2 additions & 2 deletions src/React.AspNet/HtmlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
using System.Web.Mvc;
using IHtmlHelper = System.Web.Mvc.HtmlHelper;
#else
using Microsoft.AspNet.Mvc.Rendering;
using IHtmlString = Microsoft.AspNet.Html.Abstractions.IHtmlContent;
using Microsoft.AspNetCore.Mvc.Rendering;
using IHtmlString = Microsoft.AspNetCore.Html.IHtmlContent;
#endif

#if LEGACYASPNET
Expand Down
18 changes: 2 additions & 16 deletions src/React.AspNet/HttpContextLifetimeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System;
using System.Collections.Concurrent;
using System.Linq;
using Microsoft.AspNet.Http;
using Microsoft.AspNetCore.Http;
using React.Exceptions;
using React.TinyIoC;
using Microsoft.Extensions.DependencyInjection;
Expand Down Expand Up @@ -43,28 +43,14 @@ public HttpContextLifetimeProvider(IServiceProvider appServiceProvider)
/// </summary>
private readonly string _keyName = PREFIX + Guid.NewGuid();

/// <summary>
/// Gets the <see cref="HttpContext" /> of the current request.
/// </summary>
private HttpContext HttpContext =>
_appServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;

/// <summary>
/// Gets the current per-request registrations for the current request.
/// </summary>
private PerRequestRegistrations Registrations
{
get
{
var requestServices = HttpContext.RequestServices;
if (requestServices == null)
{
throw new ReactNotInitialisedException(
"ASP.NET request services have not been initialised correctly. Please " +
"ensure you are calling app.UseRequestServices() before app.UseReact()."
);
}
var registrations = requestServices.GetService<PerRequestRegistrations>();
var registrations = _appServiceProvider.GetService<PerRequestRegistrations>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was incorrect, it wasn't handling per-request singletons properly and was instead just using a single instance for the entire app. I fixed it in a4992da 👍

if (registrations == null)
{
throw new ReactNotInitialisedException(
Expand Down
25 changes: 4 additions & 21 deletions src/React.AspNet/React.AspNet.xproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,16 @@
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
<PropertyGroup Label="Globals">
<ProjectGuid>a7acdb56-5e43-40a6-92c9-2c52228e6074</ProjectGuid>
<RootNamespace>React.AspNet</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AssemblyName>React.AspNet</AssemblyName>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\</OutputPath>
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
</PropertyGroup>
<PropertyGroup>
<SchemaVersion>2.0</SchemaVersion>
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\React.Core\React.Core.csproj" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties />
</VisualStudio>
</ProjectExtensions>
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" />
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" />
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
</Project>
8 changes: 2 additions & 6 deletions src/React.AspNet/ReactBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
*/

using System;
using Microsoft.AspNet.Builder;
using Microsoft.AspNet.Hosting;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.PlatformAbstractions;
using React.Exceptions;
using React.TinyIoC;
Expand Down Expand Up @@ -37,10 +37,6 @@ public static IApplicationBuilder UseReact(
{
EnsureServicesRegistered(app);

// Register IApplicationEnvironment in our dependency injection container
// Ideally this would be in AddReact(IServiceCollection) but we can't
// access IApplicationEnvironment there.
React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IApplicationEnvironment>());
React.AssemblyRegistration.Container.Register(app.ApplicationServices.GetRequiredService<IHostingEnvironment>());

Initializer.Initialize(registerOptions => AsPerRequestSingleton(app.ApplicationServices, registerOptions));
Expand Down
76 changes: 42 additions & 34 deletions src/React.AspNet/project.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,51 @@
{
"version": "2.3.0-*",
"configurations": {
"Debug": {
"compilationOptions": {
"define": [ "DEBUG", "TRACE", "ASPNET5" ]
}
},
"Release": {
"compilationOptions": {
"define": [ "RELEASE", "TRACE", "ASPNET5" ],
"optimize": true,
"warningsAsErrors": true
}
}
"version": "2.3.0-*",
"authors": [ "Daniel Lo Nigro" ],
"copyright": "Copyright 2014-Present Facebook, Inc",
"title": "ReactJS.NET (MVC Core)",
"description": "ReactJS and Babel tools for ASP.NET Core, including ASP.NET MVC Core. Please refer to project site (http://reactjs.net/) for full installation instructions, usage examples and sample code",
"packOptions": {
"owners": [ "Daniel Lo Nigro" ],
"licenseUrl": "https://github.com/reactjs/React.NET#licence",
"iconUrl": "http://facebook.github.io/react/img/logo_og.png",
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ],
"projectUrl": "http://reactjs.net/"
},
"configurations": {
"Debug": {
"buildOptions": {
"define": [ "DEBUG", "TRACE", "ASPNETCORE" ]
}
},
"Release": {
"buildOptions": {
"define": [ "RELEASE", "TRACE", "ASPNETCORE" ],
"optimize": true,
"warningsAsErrors": true
}
}
},
"dependencies": {
"JsPool": "0.4.1",
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-rc1-final",
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-rc1-final",
"React.Core": "2.3.0-*",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
"Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-final",
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-rc2-final",
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
"JavaScriptEngineSwitcher.Core": "1.5.0",
"JavaScriptEngineSwitcher.Msie": "1.5.0",
"JavaScriptEngineSwitcher.V8": "1.5.2",
"MsieJavaScriptEngine": "1.7.0"
"MsieJavaScriptEngine": "1.7.0",
"React.Core": {
"target": "project"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh cool, I didn't know about being able to target projects like this! Is there documentation on it?

}
},
"frameworks": {
"dnx451": { }
},

"authors": [ "Daniel Lo Nigro" ],
"owners": [ "Daniel Lo Nigro" ],
"licenseUrl": "https://github.com/reactjs/React.NET#licence",
"iconUrl": "http://facebook.github.io/react/img/logo_og.png",
"copyright": "Copyright 2014-Present Facebook, Inc",
"title": "ReactJS.NET (MVC 6)",
"description": "ReactJS and Babel tools for ASP.NET 5, including ASP.NET MVC 6. Please refer to project site (http://reactjs.net/) for full installation instructions, usage examples and sample code",
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ],
"projectUrl": "http://reactjs.net/"
"frameworks": {
"net451": {
"bin": {
"assembly": "../../bin/React.AspNet/bin/{configuration}/net451/React.AspNet.dll",
"pdb": "../../bin/React.AspNet/bin/{configuration}/net451/React.AspNet.pdb"
}
}
}
}
1 change: 1 addition & 0 deletions src/React.MSBuild/React.MSBuild.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
</ItemGroup>
<ItemGroup>
<None Include="Content\TransformBabel.proj" />
<None Include="packages.config" />
<None Include="tools\install.ps1" />
<None Include="React.MSBuild.nutrans" />
<None Include="tools\uninstall.ps1" />
Expand Down
2 changes: 1 addition & 1 deletion src/React.Sample.Mvc6/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNetCore.Mvc;
using React.Sample.Mvc6.Models;
using React.Sample.Mvc6.ViewModels;

Expand Down
Loading