Skip to content

Commit 391d3c1

Browse files
committed
add full framework example app
1 parent a882ccb commit 391d3c1

File tree

6 files changed

+245
-0
lines changed

6 files changed

+245
-0
lines changed

ExampleFrameworkApp/App.config

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
<runtime>
7+
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
8+
<dependentAssembly>
9+
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
10+
<bindingRedirect oldVersion="0.0.0.0-4.0.6.0" newVersion="4.0.6.0" />
11+
</dependentAssembly>
12+
</assemblyBinding>
13+
</runtime>
14+
</configuration>
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.props" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.props')" />
4+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
5+
<PropertyGroup>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{D27C1578-BFF9-4469-9099-DAF64450BBBE}</ProjectGuid>
9+
<OutputType>Exe</OutputType>
10+
<RootNamespace>ExampleFrameworkApp</RootNamespace>
11+
<AssemblyName>ExampleFrameworkApp</AssemblyName>
12+
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
15+
<Deterministic>true</Deterministic>
16+
<NuGetPackageImportStamp>
17+
</NuGetPackageImportStamp>
18+
</PropertyGroup>
19+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
20+
<PlatformTarget>AnyCPU</PlatformTarget>
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\Debug\</OutputPath>
25+
<DefineConstants>DEBUG;TRACE</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
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\</OutputPath>
34+
<DefineConstants>TRACE</DefineConstants>
35+
<ErrorReport>prompt</ErrorReport>
36+
<WarningLevel>4</WarningLevel>
37+
</PropertyGroup>
38+
<ItemGroup>
39+
<Reference Include="Microsoft.AspNetCore.Razor.Language, Version=3.1.5.0, Culture=neutral, PublicKeyToken=adb9793829ddae60, processorArchitecture=MSIL">
40+
<HintPath>..\packages\Microsoft.AspNetCore.Razor.Language.3.1.5\lib\netstandard2.0\Microsoft.AspNetCore.Razor.Language.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Microsoft.CodeAnalysis, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
43+
<HintPath>..\packages\Microsoft.CodeAnalysis.Common.3.6.0\lib\netstandard2.0\Microsoft.CodeAnalysis.dll</HintPath>
44+
</Reference>
45+
<Reference Include="Microsoft.CodeAnalysis.CSharp, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
46+
<HintPath>..\packages\Microsoft.CodeAnalysis.CSharp.3.6.0\lib\netstandard2.0\Microsoft.CodeAnalysis.CSharp.dll</HintPath>
47+
</Reference>
48+
<Reference Include="System" />
49+
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
50+
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
51+
</Reference>
52+
<Reference Include="System.Collections.Immutable, Version=1.2.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
53+
<HintPath>..\packages\System.Collections.Immutable.1.5.0\lib\netstandard2.0\System.Collections.Immutable.dll</HintPath>
54+
</Reference>
55+
<Reference Include="System.Core" />
56+
<Reference Include="System.Memory, Version=4.0.1.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
57+
<HintPath>..\packages\System.Memory.4.5.3\lib\netstandard2.0\System.Memory.dll</HintPath>
58+
</Reference>
59+
<Reference Include="System.Numerics" />
60+
<Reference Include="System.Numerics.Vectors, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
61+
<HintPath>..\packages\System.Numerics.Vectors.4.4.0\lib\net46\System.Numerics.Vectors.dll</HintPath>
62+
</Reference>
63+
<Reference Include="System.Reflection.Metadata, Version=1.4.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
64+
<HintPath>..\packages\System.Reflection.Metadata.1.6.0\lib\netstandard2.0\System.Reflection.Metadata.dll</HintPath>
65+
</Reference>
66+
<Reference Include="System.Runtime.CompilerServices.Unsafe, Version=4.0.6.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
67+
<HintPath>..\packages\System.Runtime.CompilerServices.Unsafe.4.7.0\lib\netstandard2.0\System.Runtime.CompilerServices.Unsafe.dll</HintPath>
68+
</Reference>
69+
<Reference Include="System.Text.Encoding.CodePages, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
70+
<HintPath>..\packages\System.Text.Encoding.CodePages.4.5.1\lib\net461\System.Text.Encoding.CodePages.dll</HintPath>
71+
</Reference>
72+
<Reference Include="System.Threading.Tasks.Extensions, Version=4.2.0.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
73+
<HintPath>..\packages\System.Threading.Tasks.Extensions.4.5.3\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll</HintPath>
74+
</Reference>
75+
<Reference Include="System.Xml.Linq" />
76+
<Reference Include="System.Data.DataSetExtensions" />
77+
<Reference Include="Microsoft.CSharp" />
78+
<Reference Include="System.Data" />
79+
<Reference Include="System.Net.Http" />
80+
<Reference Include="System.Xml" />
81+
</ItemGroup>
82+
<ItemGroup>
83+
<Compile Include="Program.cs" />
84+
<Compile Include="Properties\AssemblyInfo.cs" />
85+
</ItemGroup>
86+
<ItemGroup>
87+
<None Include="App.config" />
88+
<None Include="packages.config" />
89+
</ItemGroup>
90+
<ItemGroup>
91+
<ProjectReference Include="..\RazorEngineCore\RazorEngineCore.csproj">
92+
<Project>{1e21186e-49a5-433a-abad-18ced1aa2494}</Project>
93+
<Name>RazorEngineCore</Name>
94+
</ProjectReference>
95+
</ItemGroup>
96+
<ItemGroup>
97+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.Analyzers.dll" />
98+
<Analyzer Include="..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\analyzers\dotnet\cs\Microsoft.CodeAnalysis.CSharp.Analyzers.dll" />
99+
</ItemGroup>
100+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
101+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
102+
<PropertyGroup>
103+
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
104+
</PropertyGroup>
105+
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.props'))" />
106+
<Error Condition="!Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.targets'))" />
107+
</Target>
108+
<Import Project="..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.targets" Condition="Exists('..\packages\Microsoft.CodeAnalysis.Analyzers.3.0.0\build\Microsoft.CodeAnalysis.Analyzers.targets')" />
109+
</Project>

ExampleFrameworkApp/Program.cs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace ExampleFrameworkApp
8+
{
9+
using RazorEngineCore;
10+
11+
public class TestModel : RazorEngineTemplateBase
12+
{
13+
public string Name { get; set; }
14+
public IEnumerable<int> Items { get; set; }
15+
}
16+
17+
18+
class Program
19+
{
20+
static string Content = @"
21+
Hello @Model.Name
22+
23+
@foreach(var item in @Model.Items)
24+
{
25+
<div>- @item</div>
26+
}
27+
28+
<div data-name=""@Model.Name""></div>
29+
30+
<area>
31+
@{ RecursionTest(3); }
32+
</area>
33+
34+
@{
35+
void RecursionTest(int level){
36+
if (level <= 0)
37+
{
38+
return;
39+
}
40+
41+
<div>LEVEL: @level</div>
42+
@{ RecursionTest(level - 1); }
43+
}
44+
}";
45+
46+
static void Main(string[] args)
47+
{
48+
IRazorEngine razorEngine = new RazorEngine();
49+
IRazorEngineCompiledTemplate template = razorEngine.Compile(Content);
50+
51+
string result = template.Run(new
52+
{
53+
Name = "Alexander",
54+
Items = new List<string>()
55+
{
56+
"item 1",
57+
"item 2"
58+
}
59+
});
60+
61+
Console.WriteLine(result);
62+
Console.ReadKey();
63+
}
64+
}
65+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("ExampleFrameworkApp")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("Logical Design Solutions")]
12+
[assembly: AssemblyProduct("ExampleFrameworkApp")]
13+
[assembly: AssemblyCopyright("Copyright © Logical Design Solutions 2020")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("d27c1578-bff9-4469-9099-daf64450bbbe")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="Microsoft.AspNetCore.Razor.Language" version="3.1.5" targetFramework="net472" />
4+
<package id="Microsoft.CodeAnalysis.Analyzers" version="3.0.0" targetFramework="net472" developmentDependency="true" />
5+
<package id="Microsoft.CodeAnalysis.Common" version="3.6.0" targetFramework="net472" />
6+
<package id="Microsoft.CodeAnalysis.CSharp" version="3.6.0" targetFramework="net472" />
7+
<package id="System.Buffers" version="4.4.0" targetFramework="net472" />
8+
<package id="System.Collections.Immutable" version="1.5.0" targetFramework="net472" />
9+
<package id="System.Memory" version="4.5.3" targetFramework="net472" />
10+
<package id="System.Numerics.Vectors" version="4.4.0" targetFramework="net472" />
11+
<package id="System.Reflection.Metadata" version="1.6.0" targetFramework="net472" />
12+
<package id="System.Runtime.CompilerServices.Unsafe" version="4.7.0" targetFramework="net472" />
13+
<package id="System.Text.Encoding.CodePages" version="4.5.1" targetFramework="net472" />
14+
<package id="System.Threading.Tasks.Extensions" version="4.5.3" targetFramework="net472" />
15+
</packages>

RazorEngineCore.sln

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
Pack.ps1 = Pack.ps1
1515
EndProjectSection
1616
EndProject
17+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ExampleFrameworkApp", "ExampleFrameworkApp\ExampleFrameworkApp.csproj", "{D27C1578-BFF9-4469-9099-DAF64450BBBE}"
18+
EndProject
1719
Global
1820
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1921
Debug|Any CPU = Debug|Any CPU
@@ -32,6 +34,10 @@ Global
3234
{287FC29C-2C28-4168-8332-E1FF5BBB2721}.Debug|Any CPU.Build.0 = Debug|Any CPU
3335
{287FC29C-2C28-4168-8332-E1FF5BBB2721}.Release|Any CPU.ActiveCfg = Release|Any CPU
3436
{287FC29C-2C28-4168-8332-E1FF5BBB2721}.Release|Any CPU.Build.0 = Release|Any CPU
37+
{D27C1578-BFF9-4469-9099-DAF64450BBBE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{D27C1578-BFF9-4469-9099-DAF64450BBBE}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{D27C1578-BFF9-4469-9099-DAF64450BBBE}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{D27C1578-BFF9-4469-9099-DAF64450BBBE}.Release|Any CPU.Build.0 = Release|Any CPU
3541
EndGlobalSection
3642
GlobalSection(SolutionProperties) = preSolution
3743
HideSolutionNode = FALSE

0 commit comments

Comments
 (0)