Skip to content

Commit 0dbd639

Browse files
committed
Add console app example
This example shows how ReactJS.NET can be used outside of a web context. References reactjs#178
1 parent a81cafd commit 0dbd639

File tree

7 files changed

+205
-1
lines changed

7 files changed

+205
-1
lines changed
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<configSections>
4+
<sectionGroup name="jsEngineSwitcher">
5+
<section name="core" type="JavaScriptEngineSwitcher.Core.Configuration.CoreConfiguration, JavaScriptEngineSwitcher.Core" />
6+
<section name="v8" type="JavaScriptEngineSwitcher.V8.Configuration.V8Configuration, JavaScriptEngineSwitcher.V8" /></sectionGroup>
7+
</configSections>
8+
<startup>
9+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
10+
</startup>
11+
<jsEngineSwitcher xmlns="http://tempuri.org/JavaScriptEngineSwitcher.Configuration.xsd"><core>
12+
<engines>
13+
<add name="V8JsEngine" type="JavaScriptEngineSwitcher.V8.V8JsEngine, JavaScriptEngineSwitcher.V8" />
14+
</engines>
15+
</core></jsEngineSwitcher></configuration>
+43
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;
11+
12+
namespace React.Sample.ConsoleApp
13+
{
14+
class Program
15+
{
16+
static void Main(string[] args)
17+
{
18+
Initialize();
19+
20+
ReactSiteConfiguration.Configuration
21+
.SetReuseJavaScriptEngines(false)
22+
.AddScript("Sample.jsx");
23+
24+
var environment = React.AssemblyRegistration.Container.Resolve<IReactEnvironment>();
25+
var component = environment.CreateComponent("HelloWorld", new { name = "Daniel" });
26+
// renderServerOnly omits the data-reactid attributes
27+
var html = component.RenderHtml(renderServerOnly: true);
28+
29+
Console.WriteLine(html);
30+
Console.ReadKey();
31+
}
32+
33+
private static void Initialize()
34+
{
35+
Initializer.Initialize(registration => registration.AsSingleton());
36+
var container = React.AssemblyRegistration.Container;
37+
// Register some components that are normally provided by the integration library
38+
// (eg. React.AspNet or React.Web.Mvc6)
39+
container.Register<ICache, NullCache>();
40+
container.Register<IFileSystem, SimpleFileSystem>();
41+
}
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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.Reflection;
11+
using System.Runtime.InteropServices;
12+
13+
[assembly: AssemblyTitle("React.Sample.Console")]
14+
[assembly: AssemblyDescription("Command line sample for ReactJS.NET")]
15+
[assembly: ComVisible(false)]
16+
[assembly: Guid("350efb8e-693c-4dfe-8162-c99c359cfc71")]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{350EFB8E-693C-4DFE-8162-C99C359CFC71}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>React.Sample.ConsoleApp</RootNamespace>
11+
<AssemblyName>React.Sample.ConsoleApp</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<TargetFrameworkProfile />
16+
</PropertyGroup>
17+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
18+
<PlatformTarget>AnyCPU</PlatformTarget>
19+
<DebugSymbols>true</DebugSymbols>
20+
<DebugType>full</DebugType>
21+
<Optimize>false</Optimize>
22+
<OutputPath>..\..\bin\Debug\React.Sample.ConsoleApp\</OutputPath>
23+
<DefineConstants>DEBUG;TRACE</DefineConstants>
24+
<ErrorReport>prompt</ErrorReport>
25+
<WarningLevel>4</WarningLevel>
26+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
27+
<NoWarn>1607</NoWarn>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<PlatformTarget>AnyCPU</PlatformTarget>
31+
<DebugType>pdbonly</DebugType>
32+
<Optimize>true</Optimize>
33+
<OutputPath>..\..\bin\Release\React.Sample.ConsoleApp\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="ClearScript, Version=5.4.3.0, Culture=neutral, PublicKeyToken=935d0c957da47c73, processorArchitecture=MSIL">
40+
<HintPath>..\packages\JavaScriptEngineSwitcher.V8.1.3.0\lib\net40\ClearScript.dll</HintPath>
41+
<Private>True</Private>
42+
</Reference>
43+
<Reference Include="JavaScriptEngineSwitcher.Core, Version=1.2.4.0, Culture=neutral, PublicKeyToken=c608b2a8cc9e4472, processorArchitecture=MSIL">
44+
<HintPath>..\packages\JavaScriptEngineSwitcher.Core.1.2.4\lib\net40\JavaScriptEngineSwitcher.Core.dll</HintPath>
45+
<Private>True</Private>
46+
</Reference>
47+
<Reference Include="JavaScriptEngineSwitcher.V8, Version=1.3.0.0, Culture=neutral, PublicKeyToken=c608b2a8cc9e4472, processorArchitecture=MSIL">
48+
<HintPath>..\packages\JavaScriptEngineSwitcher.V8.1.3.0\lib\net40\JavaScriptEngineSwitcher.V8.dll</HintPath>
49+
<Private>True</Private>
50+
</Reference>
51+
<Reference Include="System" />
52+
<Reference Include="System.Core" />
53+
<Reference Include="Microsoft.CSharp" />
54+
</ItemGroup>
55+
<ItemGroup>
56+
<Compile Include="..\SharedAssemblyInfo.cs">
57+
<Link>Properties\SharedAssemblyInfo.cs</Link>
58+
</Compile>
59+
<Compile Include="..\SharedAssemblyVersionInfo.cs">
60+
<Link>Properties\SharedAssemblyVersionInfo.cs</Link>
61+
</Compile>
62+
<Compile Include="Program.cs" />
63+
<Compile Include="Properties\AssemblyInfo.cs" />
64+
</ItemGroup>
65+
<ItemGroup>
66+
<None Include="App.config" />
67+
<None Include="packages.config" />
68+
<None Include="Sample.jsx">
69+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
70+
</None>
71+
</ItemGroup>
72+
<ItemGroup>
73+
<ProjectReference Include="..\React.Core\React.Core.csproj">
74+
<Project>{d0cc8a22-cee6-485c-924b-1f94426fea59}</Project>
75+
<Name>React.Core</Name>
76+
</ProjectReference>
77+
</ItemGroup>
78+
<ItemGroup>
79+
<None Include="ClearScript.V8\ClearScriptV8-32.dll">
80+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
81+
</None>
82+
<None Include="ClearScript.V8\ClearScriptV8-64.dll">
83+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
84+
</None>
85+
<None Include="ClearScript.V8\v8-ia32.dll">
86+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
87+
</None>
88+
<None Include="ClearScript.V8\v8-x64.dll">
89+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
90+
</None>
91+
</ItemGroup>
92+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
93+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
94+
Other similar extension points exist, see Microsoft.Common.targets.
95+
<Target Name="BeforeBuild">
96+
</Target>
97+
<Target Name="AfterBuild">
98+
</Target>
99+
-->
100+
</Project>
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
var HelloWorld = React.createClass({
11+
render() {
12+
return (
13+
<div>
14+
Hello {this.props.name}!
15+
</div>
16+
);
17+
}
18+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="JavaScriptEngineSwitcher.Core" version="1.2.4" targetFramework="net4" />
4+
<package id="JavaScriptEngineSwitcher.V8" version="1.3.0" targetFramework="net4" />
5+
</packages>

src/React.VS2015.sln

+8-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.22823.1
4+
VisualStudioVersion = 14.0.23107.0
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F567B25C-E869-4C93-9C96-077761250F87}"
77
EndProject
@@ -61,6 +61,8 @@ Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "React.AspNet", "React.AspNe
6161
EndProject
6262
Project("{8BB2217D-0F2D-49D1-97BC-3654ED321F3B}") = "React.Sample.Mvc6", "React.Sample.Mvc6\React.Sample.Mvc6.xproj", "{022DC77E-5E48-4CF4-AD8B-DC4B9B52E02E}"
6363
EndProject
64+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "React.Sample.ConsoleApp", "React.Sample.ConsoleApp\React.Sample.ConsoleApp.csproj", "{350EFB8E-693C-4DFE-8162-C99C359CFC71}"
65+
EndProject
6466
Global
6567
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6668
Debug|Any CPU = Debug|Any CPU
@@ -127,6 +129,10 @@ Global
127129
{022DC77E-5E48-4CF4-AD8B-DC4B9B52E02E}.Debug|Any CPU.Build.0 = Debug|Any CPU
128130
{022DC77E-5E48-4CF4-AD8B-DC4B9B52E02E}.Release|Any CPU.ActiveCfg = Release|Any CPU
129131
{022DC77E-5E48-4CF4-AD8B-DC4B9B52E02E}.Release|Any CPU.Build.0 = Release|Any CPU
132+
{350EFB8E-693C-4DFE-8162-C99C359CFC71}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
133+
{350EFB8E-693C-4DFE-8162-C99C359CFC71}.Debug|Any CPU.Build.0 = Debug|Any CPU
134+
{350EFB8E-693C-4DFE-8162-C99C359CFC71}.Release|Any CPU.ActiveCfg = Release|Any CPU
135+
{350EFB8E-693C-4DFE-8162-C99C359CFC71}.Release|Any CPU.Build.0 = Release|Any CPU
130136
EndGlobalSection
131137
GlobalSection(SolutionProperties) = preSolution
132138
HideSolutionNode = FALSE
@@ -147,5 +153,6 @@ Global
147153
{E20376AD-80F7-4865-ACE3-1DE616991DF7} = {A51CE5B6-294F-4D39-B32B-BF08DAF9B40B}
148154
{A7ACDB56-5E43-40A6-92C9-2C52228E6074} = {681C45FB-103C-48BC-B992-20C5B6B78F92}
149155
{022DC77E-5E48-4CF4-AD8B-DC4B9B52E02E} = {A51CE5B6-294F-4D39-B32B-BF08DAF9B40B}
156+
{350EFB8E-693C-4DFE-8162-C99C359CFC71} = {A51CE5B6-294F-4D39-B32B-BF08DAF9B40B}
150157
EndGlobalSection
151158
EndGlobal

0 commit comments

Comments
 (0)