Skip to content

Commit 04f57a1

Browse files
committed
Merge pull request #94 from reactjs/asp5
ASP.NET 5 (originally vNext) support
2 parents 7a5b62b + ce39023 commit 04f57a1

34 files changed

+1334
-69
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ src/React.Sample.*/ClearScript.V8
99
src/React.Sample.Webpack/build
1010
*.generated.js
1111
*.generated.js.map
12+
src/React.Sample.Mvc6/wwwroot/js/Sample.js
1213

1314
## Ignore Visual Studio temporary files, build results, and
1415
## files generated by popular Visual Studio add-ons.

build.proj

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ of patent rights can be found in the PATENTS file in the same directory.
1010
<Project ToolsVersion="4.0" DefaultTargets="Build;Test;Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
1111
<PropertyGroup>
1212
<Major>1</Major>
13-
<Minor>3</Minor>
14-
<Build>1</Build>
13+
<Minor>4</Minor>
14+
<Build>0</Build>
1515
<Revision>0</Revision>
1616
<DevNuGetServer>http://reactjs.net/packages/</DevNuGetServer>
1717
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\tools\MSBuildTasks</MSBuildCommunityTasksPath>
18-
<SolutionFile>src\React.sln</SolutionFile>
1918
<PackageOutputDir>output</PackageOutputDir>
19+
20+
<!-- Only build ASP.NET 5 projects if on MSBuild 14+ (VS2015+) -->
21+
<BuildAspNet5>false</BuildAspNet5>
22+
<BuildAspNet5 Condition="$(VisualStudioVersion) == '14.0'">true</BuildAspNet5>
23+
<SolutionFile>src\React.VS2015.sln</SolutionFile>
24+
<SolutionFile Condition="$(BuildAspNet5) == 'false'">src\React.sln</SolutionFile>
2025
</PropertyGroup>
2126
<ItemGroup>
2227
<PackageAssemblies Include="React" />
@@ -28,14 +33,12 @@ of patent rights can be found in the PATENTS file in the same directory.
2833
<PackageAssemblies Include="React.MSBuild" />
2934
<PackageAssemblies Include="React.JavaScriptEngine.VroomJs" />
3035
<PackageAssemblies Include="React.JavaScriptEngine.ClearScriptV8" />
36+
<PackageAssembliesAspNet5 Include="React.AspNet" />
37+
<AspNet5ProjectJson Include="src/**/project.json" />
3138
</ItemGroup>
3239

33-
<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
34-
<UsingTask
35-
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll"
36-
TaskName="TransformXml"
37-
/>
38-
40+
<Import Project="src/React.tasks.proj" />
41+
3942
<Target Name="RestorePackages">
4043
<Exec
4144
WorkingDirectory="$(MSBuildProjectDirectory)"
@@ -47,27 +50,64 @@ of patent rights can be found in the PATENTS file in the same directory.
4750
<GitVersion LocalPath="$(MSBuildProjectDirectory)">
4851
<Output TaskParameter="CommitHash" PropertyName="Revision" />
4952
</GitVersion>
50-
<!--TODO: Only do this if a dev build -->
5153
<Time Format="yyyyMMdd-HHmm">
5254
<Output TaskParameter="FormattedTime" PropertyName="Date" />
5355
</Time>
5456
<!-- Prepend date to build version if a dev build-->
57+
<PropertyGroup Condition="$(BuildType) == 'Release'">
58+
<FullBuild>$(Build)</FullBuild>
59+
</PropertyGroup>
5560
<PropertyGroup Condition="$(BuildType) != 'Release'">
56-
<Build>$(Build)-dev-$(Date)</Build>
61+
<FullBuild>$(Build)-dev-$(Date)</FullBuild>
5762
</PropertyGroup>
63+
<!-- Set version for .csproj projects -->
5864
<AssemblyInfo
5965
CodeLanguage="CS"
6066
OutputFile="src\SharedAssemblyVersionInfo.cs"
6167
AssemblyVersion="$(Major).$(Minor)"
62-
AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
63-
AssemblyInformationalVersion="$(Major).$(Minor).$(Build)"
64-
/>
68+
AssemblyFileVersion="$(Major).$(Minor).$(FullBuild).$(Revision)"
69+
AssemblyInformationalVersion="$(Major).$(Minor).$(FullBuild)"
70+
/>
71+
<!--
72+
Set version for ASP.NET 5 projects. In theory K_BUILD_VERSION should work but it doesn't seem
73+
to be functional yet :(. We work around this by physically writing the build number to the
74+
project.json files. For development builds we write the full version number (including
75+
build date) and reset it later so the dev build number isn't commited to the repo.
76+
-->
77+
<!--SetEnvironmentVariable
78+
Condition="$(BuildAspNet5) == 'true'"
79+
Name="K_BUILD_VERSION"
80+
Value="$(Build)"
81+
/-->
82+
<UpdateAspNetProjectVersion
83+
Files="@(AspNet5ProjectJson)"
84+
Version="$(Major).$(Minor).$(FullBuild)"
85+
/>
86+
</Target>
87+
88+
<Target Name="Clean" BeforeTargets="Build">
89+
<!--
90+
ASP.NET 5 projects don't delete generated .nupkg files when cleaned or rebuilt, so we need to
91+
do it here. See https://github.com/aspnet/XRE/issues/1301
92+
-->
93+
<ItemGroup>
94+
<OldAspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/**/*.nupkg" />
95+
</ItemGroup>
96+
<Delete Files="@(OldAspNet5Packages)" />
6597
</Target>
6698

6799
<Target Name="Build" DependsOnTargets="RestorePackages;UpdateVersion">
68100
<MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=Release;Platform=Any CPU;NoWarn=1607" />
69101
</Target>
70102

103+
<Target Name="ResetAspNetVersion" AfterTargets="Build">
104+
<!-- Resets the version number in ASP.NET project.json files so we don't commit -dev- version numbers -->
105+
<UpdateAspNetProjectVersion
106+
Files="@(AspNet5ProjectJson)"
107+
Version="$(Major).$(Minor).$(Build)-*"
108+
/>
109+
</Target>
110+
71111
<Target Name="Test" DependsOnTargets="Build">
72112
<ItemGroup>
73113
<TestAssemblies Include="bin/ReleaseTests/**/React.Tests*.dll" />
@@ -98,6 +138,14 @@ of patent rights can be found in the PATENTS file in the same directory.
98138
/>
99139
</Target>
100140

141+
<Target Name="CopyAspNetPackages" AfterTargets="Package" Condition="$(BuildAspNet5) == 'true'">
142+
<!-- Copy over ASP.NET 5 packages -->
143+
<ItemGroup>
144+
<AspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/Release/*.nupkg" />
145+
</ItemGroup>
146+
<Copy SourceFiles="@(AspNet5Packages)" DestinationFolder="output" />
147+
</Target>
148+
101149
<Target Name="Push">
102150
<CallTarget Targets="PushDev" Condition="$(BuildType) != 'Release'" />
103151
<CallTarget Targets="PushRelease" Condition="$(BuildType) == 'Release'" />

dev-build-push.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@echo off
2-
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
2+
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
3+
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
4+
) ELSE (
5+
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
6+
)
37
pause

dev-build-vs2015.bat

Lines changed: 0 additions & 3 deletions
This file was deleted.

dev-build.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@echo off
2-
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
2+
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
3+
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
4+
) ELSE (
5+
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
6+
)
37
pause

release-build-push.bat

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
@echo off
2-
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
2+
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
3+
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
4+
) ELSE (
5+
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
6+
)
37
pause

release-build.bat

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
11
@echo off
2-
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
2+
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
3+
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
4+
) ELSE (
5+
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
6+
)
7+
pause
38
pause

src/React.AspNet/AspNetFileSystem.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using System.IO;
11+
using Microsoft.Framework.Runtime;
12+
13+
namespace React.AspNet
14+
{
15+
/// <summary>
16+
/// Handles file system functionality, such as reading files. Maps all paths from
17+
/// application-relative (~/...) to full paths using ASP.NET's MapPath method.
18+
/// </summary>
19+
public class AspNetFileSystem : FileSystemBase
20+
{
21+
private readonly IApplicationEnvironment _appEnvironment;
22+
23+
/// <summary>
24+
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
25+
/// </summary>
26+
/// <param name="appEnvironment">The ASP.NET 5 application environment</param>
27+
public AspNetFileSystem(IApplicationEnvironment appEnvironment)
28+
{
29+
_appEnvironment = appEnvironment;
30+
}
31+
32+
/// <summary>
33+
/// Converts a path from an application relative path (~/...) to a full filesystem path
34+
/// </summary>
35+
/// <param name="relativePath">App-relative path of the file</param>
36+
/// <returns>Full path of the file</returns>
37+
public override string MapPath(string relativePath)
38+
{
39+
relativePath = relativePath.TrimStart('~').TrimStart('/');
40+
return Path.Combine(_appEnvironment.ApplicationBasePath, relativePath);
41+
}
42+
}
43+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) 2015, Facebook, Inc.
3+
* All rights reserved.
4+
*
5+
* This source code is licensed under the BSD-style license found in the
6+
* LICENSE file in the root directory of this source tree. An additional grant
7+
* of patent rights can be found in the PATENTS file in the same directory.
8+
*/
9+
10+
using React.TinyIoC;
11+
12+
namespace React.AspNet
13+
{
14+
/// <summary>
15+
/// Handles registration of ReactJS.NET components that are only applicable
16+
/// in the context of an ASP.NET web application.
17+
/// </summary>
18+
public class AssemblyRegistration : IAssemblyRegistration
19+
{
20+
/// <summary>
21+
/// Registers components in the React IoC container
22+
/// </summary>
23+
/// <param name="container">Container to register components in</param>
24+
public void Register(TinyIoCContainer container)
25+
{
26+
container.Register<IFileSystem, AspNetFileSystem>().AsSingleton();
27+
container.Register<ICache, MemoryFileCache>().AsSingleton();
28+
}
29+
}
30+
}

src/React.Web.Mvc4/HtmlHelperExtensions.cs renamed to src/React.AspNet/HtmlHelperExtensions.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,34 @@
77
* of patent rights can be found in the PATENTS file in the same directory.
88
*/
99

10+
#if LEGACYASPNET
1011
using System.Web;
1112
using System.Web.Mvc;
13+
using IHtmlHelper = System.Web.Mvc.HtmlHelper;
14+
#else
15+
using Microsoft.AspNet.Mvc.Rendering;
16+
using IHtmlString = Microsoft.AspNet.Mvc.Rendering.HtmlString;
17+
#endif
1218

19+
#if LEGACYASPNET
1320
namespace React.Web.Mvc
21+
#else
22+
namespace React.AspNet
23+
#endif
1424
{
15-
using AssemblyRegistration = React.AssemblyRegistration;
16-
1725
/// <summary>
1826
/// HTML Helpers for utilising React from an ASP.NET MVC application.
1927
/// </summary>
2028
public static class HtmlHelperExtensions
2129
{
30+
2231
/// <summary>
2332
/// Gets the React environment
2433
/// </summary>
2534
private static IReactEnvironment Environment
2635
{
2736
// TODO: Figure out if this can be injected
28-
get { return AssemblyRegistration.Container.Resolve<IReactEnvironment>(); }
37+
get { return global::React.AssemblyRegistration.Container.Resolve<IReactEnvironment>(); }
2938
}
3039

3140
/// <summary>
@@ -39,8 +48,8 @@ private static IReactEnvironment Environment
3948
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
4049
/// <returns>The component's HTML</returns>
4150
public static IHtmlString React<T>(
42-
this HtmlHelper htmlHelper,
43-
string componentName,
51+
this IHtmlHelper htmlHelper,
52+
string componentName,
4453
T props,
4554
string htmlTag = null,
4655
string containerId = null
@@ -68,7 +77,7 @@ public static IHtmlString React<T>(
6877
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
6978
/// <returns>The component's HTML</returns>
7079
public static IHtmlString ReactWithInit<T>(
71-
this HtmlHelper htmlHelper,
80+
this IHtmlHelper htmlHelper,
7281
string componentName,
7382
T props,
7483
string htmlTag = null,
@@ -93,7 +102,7 @@ public static IHtmlString ReactWithInit<T>(
93102
/// attach event handlers to the server-rendered HTML.
94103
/// </summary>
95104
/// <returns>JavaScript for all components</returns>
96-
public static IHtmlString ReactInitJavaScript(this HtmlHelper htmlHelper)
105+
public static IHtmlString ReactInitJavaScript(this IHtmlHelper htmlHelper)
97106
{
98107
var script = Environment.GetInitJavaScript();
99108
var tag = new TagBuilder("script")
@@ -103,4 +112,4 @@ public static IHtmlString ReactInitJavaScript(this HtmlHelper htmlHelper)
103112
return new HtmlString(tag.ToString());
104113
}
105114
}
106-
}
115+
}

0 commit comments

Comments
 (0)