Skip to content

ASP.NET 5 (originally vNext) support #94

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 9 commits into from
Feb 28, 2015
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ src/React.Sample.*/ClearScript.V8
src/React.Sample.Webpack/build
*.generated.js
*.generated.js.map
src/React.Sample.Mvc6/wwwroot/js/Sample.js

## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
Expand Down
76 changes: 62 additions & 14 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ of patent rights can be found in the PATENTS file in the same directory.
<Project ToolsVersion="4.0" DefaultTargets="Build;Test;Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Major>1</Major>
<Minor>3</Minor>
<Build>1</Build>
<Minor>4</Minor>
<Build>0</Build>
<Revision>0</Revision>
<DevNuGetServer>http://reactjs.net/packages/</DevNuGetServer>
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\tools\MSBuildTasks</MSBuildCommunityTasksPath>
<SolutionFile>src\React.sln</SolutionFile>
<PackageOutputDir>output</PackageOutputDir>

<!-- Only build ASP.NET 5 projects if on MSBuild 14+ (VS2015+) -->
<BuildAspNet5>false</BuildAspNet5>
<BuildAspNet5 Condition="$(VisualStudioVersion) == '14.0'">true</BuildAspNet5>
<SolutionFile>src\React.VS2015.sln</SolutionFile>
<SolutionFile Condition="$(BuildAspNet5) == 'false'">src\React.sln</SolutionFile>
</PropertyGroup>
<ItemGroup>
<PackageAssemblies Include="React" />
Expand All @@ -28,14 +33,12 @@ of patent rights can be found in the PATENTS file in the same directory.
<PackageAssemblies Include="React.MSBuild" />
<PackageAssemblies Include="React.JavaScriptEngine.VroomJs" />
<PackageAssemblies Include="React.JavaScriptEngine.ClearScriptV8" />
<PackageAssembliesAspNet5 Include="React.AspNet" />
<AspNet5ProjectJson Include="src/**/project.json" />
</ItemGroup>

<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
<UsingTask
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll"
TaskName="TransformXml"
/>

<Import Project="src/React.tasks.proj" />

<Target Name="RestorePackages">
<Exec
WorkingDirectory="$(MSBuildProjectDirectory)"
Expand All @@ -47,27 +50,64 @@ of patent rights can be found in the PATENTS file in the same directory.
<GitVersion LocalPath="$(MSBuildProjectDirectory)">
<Output TaskParameter="CommitHash" PropertyName="Revision" />
</GitVersion>
<!--TODO: Only do this if a dev build -->
<Time Format="yyyyMMdd-HHmm">
<Output TaskParameter="FormattedTime" PropertyName="Date" />
</Time>
<!-- Prepend date to build version if a dev build-->
<PropertyGroup Condition="$(BuildType) == 'Release'">
<FullBuild>$(Build)</FullBuild>
</PropertyGroup>
<PropertyGroup Condition="$(BuildType) != 'Release'">
<Build>$(Build)-dev-$(Date)</Build>
<FullBuild>$(Build)-dev-$(Date)</FullBuild>
</PropertyGroup>
<!-- Set version for .csproj projects -->
<AssemblyInfo
CodeLanguage="CS"
OutputFile="src\SharedAssemblyVersionInfo.cs"
AssemblyVersion="$(Major).$(Minor)"
AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
AssemblyInformationalVersion="$(Major).$(Minor).$(Build)"
/>
AssemblyFileVersion="$(Major).$(Minor).$(FullBuild).$(Revision)"
AssemblyInformationalVersion="$(Major).$(Minor).$(FullBuild)"
/>
<!--
Set version for ASP.NET 5 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.
-->
<!--SetEnvironmentVariable
Condition="$(BuildAspNet5) == 'true'"
Name="K_BUILD_VERSION"
Value="$(Build)"
/-->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
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
do it here. See https://github.com/aspnet/XRE/issues/1301
-->
<ItemGroup>
<OldAspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/**/*.nupkg" />
</ItemGroup>
<Delete Files="@(OldAspNet5Packages)" />
</Target>

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

<Target Name="ResetAspNetVersion" AfterTargets="Build">
<!-- Resets the version number in ASP.NET project.json files so we don't commit -dev- version numbers -->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
Version="$(Major).$(Minor).$(Build)-*"
/>
</Target>

<Target Name="Test" DependsOnTargets="Build">
<ItemGroup>
<TestAssemblies Include="bin/ReleaseTests/**/React.Tests*.dll" />
Expand Down Expand Up @@ -98,6 +138,14 @@ of patent rights can be found in the PATENTS file in the same directory.
/>
</Target>

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

<Target Name="Push">
<CallTarget Targets="PushDev" Condition="$(BuildType) != 'Release'" />
<CallTarget Targets="PushRelease" Condition="$(BuildType) == 'Release'" />
Expand Down
6 changes: 5 additions & 1 deletion dev-build-push.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
)
pause
3 changes: 0 additions & 3 deletions dev-build-vs2015.bat

This file was deleted.

6 changes: 5 additions & 1 deletion dev-build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
)
pause
6 changes: 5 additions & 1 deletion release-build-push.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
)
pause
7 changes: 6 additions & 1 deletion release-build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
)
pause
pause
43 changes: 43 additions & 0 deletions src/React.AspNet/AspNetFileSystem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

using System.IO;
using Microsoft.Framework.Runtime;

namespace React.AspNet
{
/// <summary>
/// Handles file system functionality, such as reading files. Maps all paths from
/// application-relative (~/...) to full paths using ASP.NET's MapPath method.
/// </summary>
public class AspNetFileSystem : FileSystemBase
{
private readonly IApplicationEnvironment _appEnvironment;

/// <summary>
/// Initializes a new instance of the <see cref="AspNetFileSystem"/> class.
/// </summary>
/// <param name="appEnvironment">The ASP.NET 5 application environment</param>
public AspNetFileSystem(IApplicationEnvironment appEnvironment)
{
_appEnvironment = appEnvironment;
}

/// <summary>
/// Converts a path from an application relative path (~/...) to a full filesystem path
/// </summary>
/// <param name="relativePath">App-relative path of the file</param>
/// <returns>Full path of the file</returns>
public override string MapPath(string relativePath)
{
relativePath = relativePath.TrimStart('~').TrimStart('/');
return Path.Combine(_appEnvironment.ApplicationBasePath, relativePath);
}
}
}
30 changes: 30 additions & 0 deletions src/React.AspNet/AssemblyRegistration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) 2015, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*/

using React.TinyIoC;

namespace React.AspNet
{
/// <summary>
/// Handles registration of ReactJS.NET components that are only applicable
/// in the context of an ASP.NET web application.
/// </summary>
public class AssemblyRegistration : IAssemblyRegistration
{
/// <summary>
/// Registers components in the React IoC container
/// </summary>
/// <param name="container">Container to register components in</param>
public void Register(TinyIoCContainer container)
{
container.Register<IFileSystem, AspNetFileSystem>().AsSingleton();
container.Register<ICache, MemoryFileCache>().AsSingleton();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,34 @@
* of patent rights can be found in the PATENTS file in the same directory.
*/

#if LEGACYASPNET
using System.Web;
using System.Web.Mvc;
using IHtmlHelper = System.Web.Mvc.HtmlHelper;
#else
using Microsoft.AspNet.Mvc.Rendering;
using IHtmlString = Microsoft.AspNet.Mvc.Rendering.HtmlString;
#endif

#if LEGACYASPNET
namespace React.Web.Mvc
#else
namespace React.AspNet
#endif
{
using AssemblyRegistration = React.AssemblyRegistration;

/// <summary>
/// HTML Helpers for utilising React from an ASP.NET MVC application.
/// </summary>
public static class HtmlHelperExtensions
{

/// <summary>
/// Gets the React environment
/// </summary>
private static IReactEnvironment Environment
{
// TODO: Figure out if this can be injected
get { return AssemblyRegistration.Container.Resolve<IReactEnvironment>(); }
get { return global::React.AssemblyRegistration.Container.Resolve<IReactEnvironment>(); }
}

/// <summary>
Expand All @@ -39,8 +48,8 @@ private static IReactEnvironment Environment
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
/// <returns>The component's HTML</returns>
public static IHtmlString React<T>(
this HtmlHelper htmlHelper,
string componentName,
this IHtmlHelper htmlHelper,
string componentName,
T props,
string htmlTag = null,
string containerId = null
Expand Down Expand Up @@ -68,7 +77,7 @@ public static IHtmlString React<T>(
/// <param name="containerId">ID to use for the container HTML tag. Defaults to an auto-generated ID</param>
/// <returns>The component's HTML</returns>
public static IHtmlString ReactWithInit<T>(
this HtmlHelper htmlHelper,
this IHtmlHelper htmlHelper,
string componentName,
T props,
string htmlTag = null,
Expand All @@ -93,7 +102,7 @@ public static IHtmlString ReactWithInit<T>(
/// attach event handlers to the server-rendered HTML.
/// </summary>
/// <returns>JavaScript for all components</returns>
public static IHtmlString ReactInitJavaScript(this HtmlHelper htmlHelper)
public static IHtmlString ReactInitJavaScript(this IHtmlHelper htmlHelper)
{
var script = Environment.GetInitJavaScript();
var tag = new TagBuilder("script")
Expand All @@ -103,4 +112,4 @@ public static IHtmlString ReactInitJavaScript(this HtmlHelper htmlHelper)
return new HtmlString(tag.ToString());
}
}
}
}
Loading