Skip to content

Commit fe6f54f

Browse files
ShikiGamiDaniel15
authored andcommitted
Making React.AspNet compatible with ASP.NET Core RC2 (#271)
1 parent 4887288 commit fe6f54f

27 files changed

+234
-196
lines changed

appveyor.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@ version: '{build}'
22
os: Visual Studio 2015
33
install:
44
- set PATH=%ProgramFiles(x86)%\MSBuild\14.0\Bin;%PATH%
5-
- dnvm update-self
6-
- dnvm install 1.0.0-rc1-update1
75
build:
86
project: build.proj
97
verbosity: normal

build.proj

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ of patent rights can be found in the PATENTS file in the same directory.
2929
<PackageAssemblies Include="Cassette.React" />
3030
<PackageAssemblies Include="React.MSBuild" />
3131
<PackageAssemblies Include="React.Owin" />
32-
<PackageAssembliesAspNet5 Include="React.AspNet" />
33-
<AspNet5ProjectJson Include="src/React.AspNet/project.json" />
34-
<AspNet5ProjectJson Include="src/React.Sample.Mvc6/project.json" />
35-
<AspNet5ProjectJson Include="src/wrap/**/project.json" />
32+
<PackageAssembliesAspNetCore Include="React.AspNet" />
33+
<AspNetCoreProjectJson Include="src/wrap/**/project.json" />
34+
<AspNetCoreProjectJson Include="src/React.AspNet/project.json" />
35+
<AspNetCoreProjectJson Include="src/React.Sample.Mvc6/project.json" />
3636
</ItemGroup>
3737

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

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

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

114-
<Target Name="ResetAspNetVersion" AfterTargets="Build">
115-
<!-- Resets the version number in ASP.NET project.json files so we don't commit -dev- version numbers -->
114+
<Target Name="ResetAspNetVersion" AfterTargets="AspNetPackages">
115+
<!-- Resets the version number in ASP.NET Core project.json files so we don't commit -dev- version numbers -->
116116
<UpdateAspNetProjectVersion
117-
Files="@(AspNet5ProjectJson)"
117+
Files="@(AspNetCoreProjectJson)"
118118
Version="$(Major).$(Minor).$(Build)-*"
119119
/>
120120
</Target>
@@ -148,13 +148,12 @@ of patent rights can be found in the PATENTS file in the same directory.
148148
Command="tools\NuGet\nuget.exe pack src/%(PackageAssemblies.Identity)/%(PackageAssemblies.Identity).csproj -IncludeReferencedProjects -Symbols -Prop Configuration=Release -OutputDirectory output"
149149
/>
150150
</Target>
151-
152-
<Target Name="CopyAspNetPackages" AfterTargets="Package">
153-
<!-- Copy over ASP.NET 5 packages -->
154-
<ItemGroup>
155-
<AspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/Release/*.nupkg" />
156-
</ItemGroup>
157-
<Copy SourceFiles="@(AspNet5Packages)" DestinationFolder="$(PackageOutputDir)" />
151+
152+
<Target Name="AspNetPackages" AfterTargets="Package">
153+
<Exec
154+
WorkingDirectory="$(MSBuildProjectDirectory)"
155+
Command="dotnet pack --output $(PackageOutputDir) --build-base-path bin/ --configuration Release --no-build src/%(PackageAssembliesAspNetCore.Identity)/project.json"
156+
/>
158157
</Target>
159158

160159
<Target Name="Push">

src/React.AspNet/AspNetFileSystem.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99

1010
using System.IO;
11-
using Microsoft.AspNet.Hosting;
11+
using Microsoft.AspNetCore.Hosting;
1212

1313
namespace React.AspNet
1414
{

src/React.AspNet/BabelFileMiddleware.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
using System;
1111
using System.Linq;
1212
using System.Threading.Tasks;
13-
using Microsoft.AspNet.Builder;
14-
using Microsoft.AspNet.Hosting;
15-
using Microsoft.AspNet.Http;
16-
using Microsoft.AspNet.StaticFiles;
13+
using Microsoft.AspNetCore.Builder;
14+
using Microsoft.AspNetCore.Hosting;
15+
using Microsoft.AspNetCore.Http;
16+
using Microsoft.AspNetCore.StaticFiles;
1717
using Microsoft.Extensions.Logging;
18+
using Microsoft.Extensions.Options;
1819

1920
namespace React.AspNet
2021
{
@@ -76,19 +77,19 @@ private StaticFileMiddleware CreateFileMiddleware(IBabel babel)
7677
return new StaticFileMiddleware(
7778
_next,
7879
_hostingEnv,
79-
new StaticFileOptions
80+
Options.Create(new StaticFileOptions
8081
{
8182
ContentTypeProvider = _options.StaticFileOptions.ContentTypeProvider,
8283
DefaultContentType = _options.StaticFileOptions.DefaultContentType,
8384
OnPrepareResponse = _options.StaticFileOptions.OnPrepareResponse,
8485
RequestPath = _options.StaticFileOptions.RequestPath,
8586
ServeUnknownFileTypes = _options.StaticFileOptions.ServeUnknownFileTypes,
8687
FileProvider = new BabelFileSystem(
87-
babel,
88+
babel,
8889
_options.StaticFileOptions.FileProvider ?? _hostingEnv.WebRootFileProvider,
8990
_options.Extensions
9091
)
91-
},
92+
}),
9293
_loggerFactory
9394
);
9495
}

src/React.AspNet/BabelFileOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#if OWIN
1212
using Microsoft.Owin.StaticFiles;
1313
#else
14-
using Microsoft.AspNet.StaticFiles;
14+
using Microsoft.AspNetCore.Builder;
1515
#endif
1616

1717
#if OWIN

src/React.AspNet/BabelFileSystem.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
using Microsoft.Owin.FileSystems;
1717
using IOwinFileSystem = Microsoft.Owin.FileSystems.IFileSystem;
1818
#else
19-
using Microsoft.AspNet.FileProviders;
19+
using Microsoft.Extensions.FileProviders;
2020
using Microsoft.Extensions.Primitives;
21-
using IOwinFileSystem = Microsoft.AspNet.FileProviders.IFileProvider;
22-
using PhysicalFileSystem = Microsoft.AspNet.FileProviders.PhysicalFileProvider;
21+
using IOwinFileSystem = Microsoft.Extensions.FileProviders.IFileProvider;
22+
using PhysicalFileSystem = Microsoft.Extensions.FileProviders.PhysicalFileProvider;
2323
#endif
2424

2525
#if OWIN

src/React.AspNet/HtmlHelperExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
using System.Web.Mvc;
1616
using IHtmlHelper = System.Web.Mvc.HtmlHelper;
1717
#else
18-
using Microsoft.AspNet.Mvc.Rendering;
19-
using IHtmlString = Microsoft.AspNet.Html.Abstractions.IHtmlContent;
18+
using Microsoft.AspNetCore.Mvc.Rendering;
19+
using IHtmlString = Microsoft.AspNetCore.Html.IHtmlContent;
2020
#endif
2121

2222
#if LEGACYASPNET

src/React.AspNet/HttpContextLifetimeProvider.cs

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using System;
1111
using System.Collections.Concurrent;
1212
using System.Linq;
13-
using Microsoft.AspNet.Http;
13+
using Microsoft.AspNetCore.Http;
1414
using React.Exceptions;
1515
using React.TinyIoC;
1616
using Microsoft.Extensions.DependencyInjection;
@@ -43,28 +43,14 @@ public HttpContextLifetimeProvider(IServiceProvider appServiceProvider)
4343
/// </summary>
4444
private readonly string _keyName = PREFIX + Guid.NewGuid();
4545

46-
/// <summary>
47-
/// Gets the <see cref="HttpContext" /> of the current request.
48-
/// </summary>
49-
private HttpContext HttpContext =>
50-
_appServiceProvider.GetRequiredService<IHttpContextAccessor>().HttpContext;
51-
5246
/// <summary>
5347
/// Gets the current per-request registrations for the current request.
5448
/// </summary>
5549
private PerRequestRegistrations Registrations
5650
{
5751
get
5852
{
59-
var requestServices = HttpContext.RequestServices;
60-
if (requestServices == null)
61-
{
62-
throw new ReactNotInitialisedException(
63-
"ASP.NET request services have not been initialised correctly. Please " +
64-
"ensure you are calling app.UseRequestServices() before app.UseReact()."
65-
);
66-
}
67-
var registrations = requestServices.GetService<PerRequestRegistrations>();
53+
var registrations = _appServiceProvider.GetService<PerRequestRegistrations>();
6854
if (registrations == null)
6955
{
7056
throw new ReactNotInitialisedException(

src/React.AspNet/React.AspNet.xproj

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,16 @@
44
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">14.0</VisualStudioVersion>
55
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
66
</PropertyGroup>
7+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.Props" Condition="'$(VSToolsPath)' != ''" />
78
<PropertyGroup Label="Globals">
89
<ProjectGuid>a7acdb56-5e43-40a6-92c9-2c52228e6074</ProjectGuid>
910
<RootNamespace>React.AspNet</RootNamespace>
1011
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
11-
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\$(MSBuildProjectName)\</OutputPath>
12-
</PropertyGroup>
13-
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
14-
<AssemblyName>React.AspNet</AssemblyName>
12+
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\</OutputPath>
13+
<TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
1514
</PropertyGroup>
1615
<PropertyGroup>
1716
<SchemaVersion>2.0</SchemaVersion>
18-
<TypeScriptCompileBlocked>True</TypeScriptCompileBlocked>
19-
</PropertyGroup>
20-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
21-
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
22-
</PropertyGroup>
23-
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
24-
<ProduceOutputsOnBuild>True</ProduceOutputsOnBuild>
2517
</PropertyGroup>
26-
<ItemGroup>
27-
<ProjectReference Include="..\React.Core\React.Core.csproj" />
28-
</ItemGroup>
29-
<ProjectExtensions>
30-
<VisualStudio>
31-
<UserProperties />
32-
</VisualStudio>
33-
</ProjectExtensions>
34-
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.Props" />
35-
<Import Project="$(VSToolsPath)\DNX\Microsoft.DNX.targets" />
18+
<Import Project="$(VSToolsPath)\DotNet\Microsoft.DotNet.targets" Condition="'$(VSToolsPath)' != ''" />
3619
</Project>

src/React.AspNet/ReactBuilderExtensions.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
*/
99

1010
using System;
11-
using Microsoft.AspNet.Builder;
12-
using Microsoft.AspNet.Hosting;
11+
using Microsoft.AspNetCore.Builder;
12+
using Microsoft.AspNetCore.Hosting;
1313
using Microsoft.Extensions.PlatformAbstractions;
1414
using React.Exceptions;
1515
using React.TinyIoC;
@@ -37,10 +37,6 @@ public static IApplicationBuilder UseReact(
3737
{
3838
EnsureServicesRegistered(app);
3939

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

4642
Initializer.Initialize(registerOptions => AsPerRequestSingleton(app.ApplicationServices, registerOptions));

src/React.AspNet/project.json

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,51 @@
11
{
2-
"version": "2.3.0-*",
3-
"configurations": {
4-
"Debug": {
5-
"compilationOptions": {
6-
"define": [ "DEBUG", "TRACE", "ASPNET5" ]
7-
}
8-
},
9-
"Release": {
10-
"compilationOptions": {
11-
"define": [ "RELEASE", "TRACE", "ASPNET5" ],
12-
"optimize": true,
13-
"warningsAsErrors": true
14-
}
15-
}
2+
"version": "2.3.0-*",
3+
"authors": [ "Daniel Lo Nigro" ],
4+
"copyright": "Copyright 2014-Present Facebook, Inc",
5+
"title": "ReactJS.NET (MVC Core)",
6+
"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",
7+
"packOptions": {
8+
"owners": [ "Daniel Lo Nigro" ],
9+
"licenseUrl": "https://github.com/reactjs/React.NET#licence",
10+
"iconUrl": "http://facebook.github.io/react/img/logo_og.png",
11+
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ],
12+
"projectUrl": "http://reactjs.net/"
13+
},
14+
"configurations": {
15+
"Debug": {
16+
"buildOptions": {
17+
"define": [ "DEBUG", "TRACE", "ASPNETCORE" ]
18+
}
1619
},
20+
"Release": {
21+
"buildOptions": {
22+
"define": [ "RELEASE", "TRACE", "ASPNETCORE" ],
23+
"optimize": true,
24+
"warningsAsErrors": true
25+
}
26+
}
27+
},
1728
"dependencies": {
1829
"JsPool": "0.4.1",
19-
"Microsoft.AspNet.Mvc.Core": "6.0.0-rc1-final",
20-
"Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
21-
"Microsoft.AspNet.FileProviders.Physical": "1.0.0-rc1-final",
22-
"Microsoft.AspNet.Mvc.ViewFeatures": "6.0.0-rc1-final",
23-
"React.Core": "2.3.0-*",
24-
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc1-final",
30+
"Microsoft.AspNetCore.Mvc.Core": "1.0.0-rc2-final",
31+
"Microsoft.AspNetCore.StaticFiles": "1.0.0-rc2-final",
32+
"Microsoft.Extensions.FileProviders.Physical": "1.0.0-rc2-final",
33+
"Microsoft.AspNetCore.Mvc.ViewFeatures": "1.0.0-rc2-final",
34+
"Microsoft.Extensions.DependencyInjection": "1.0.0-rc2-final",
2535
"JavaScriptEngineSwitcher.Core": "1.5.0",
2636
"JavaScriptEngineSwitcher.Msie": "1.5.0",
2737
"JavaScriptEngineSwitcher.V8": "1.5.2",
28-
"MsieJavaScriptEngine": "1.7.0"
38+
"MsieJavaScriptEngine": "1.7.0",
39+
"React.Core": {
40+
"target": "project"
41+
}
2942
},
30-
"frameworks": {
31-
"dnx451": { }
32-
},
33-
34-
"authors": [ "Daniel Lo Nigro" ],
35-
"owners": [ "Daniel Lo Nigro" ],
36-
"licenseUrl": "https://github.com/reactjs/React.NET#licence",
37-
"iconUrl": "http://facebook.github.io/react/img/logo_og.png",
38-
"copyright": "Copyright 2014-Present Facebook, Inc",
39-
"title": "ReactJS.NET (MVC 6)",
40-
"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",
41-
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ],
42-
"projectUrl": "http://reactjs.net/"
43+
"frameworks": {
44+
"net451": {
45+
"bin": {
46+
"assembly": "../../bin/React.AspNet/bin/{configuration}/net451/React.AspNet.dll",
47+
"pdb": "../../bin/React.AspNet/bin/{configuration}/net451/React.AspNet.pdb"
48+
}
49+
}
50+
}
4351
}

src/React.MSBuild/React.MSBuild.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
</ItemGroup>
6868
<ItemGroup>
6969
<None Include="Content\TransformBabel.proj" />
70+
<None Include="packages.config" />
7071
<None Include="tools\install.ps1" />
7172
<None Include="React.MSBuild.nutrans" />
7273
<None Include="tools\uninstall.ps1" />

src/React.Sample.Mvc6/Controllers/HomeController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
using System.Collections.Generic;
1414
using System.Linq;
15-
using Microsoft.AspNet.Mvc;
15+
using Microsoft.AspNetCore.Mvc;
1616
using React.Sample.Mvc6.Models;
1717
using React.Sample.Mvc6.ViewModels;
1818

0 commit comments

Comments
 (0)