Skip to content

Commit e512287

Browse files
committed
Added file nesting support
1 parent 296c9bd commit e512287

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ packages
1212
*.received.*
1313
.vs
1414
*.nupkg
15-
*.generated.cs
15+
*.cshtml.cs

MSBuildRazorCompiler/CompileRazorFiles.targets

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

1919
<Target Name="CleanCompiledRazorFiles" BeforeTargets="CoreClean">
2020
<ItemGroup>
21-
<_CustomFilesToDelete Include="**\**\*.cshtml.generated.cs"/>
21+
<_CustomFilesToDelete Include="**\**\*.cshtml.cs"/>
2222
</ItemGroup>
2323
<Delete Files='@(_CustomFilesToDelete)'/>
2424
</Target>

MSBuildRazorCompiler/Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ static int Main(string[] args)
5252
.Replace("namespace RazorLight.CompiledTemplates", $"namespace {namespacePath}")
5353
.Replace("typeof(RazorLight.CompiledTemplates.GeneratedTemplate)", $"typeof({namespacePath}.{className})");
5454

55-
Console.WriteLine($" Writing {file}.generated.cs");
56-
File.WriteAllText(file + ".generated.cs", code, Encoding.UTF8);
55+
Console.WriteLine($" Writing {file}.cs");
56+
File.WriteAllText(file + ".cs", code, Encoding.UTF8);
5757
}
5858

5959
return 0;

README.md

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Because this library generates `.cs` files you don't need to worry about compila
1818

1919
1. Include `SomeFile.cshtml` in your (netcoreapp3.1) project
2020
2. `Install-Package MSBuildRazorCompiler`
21-
3. Compile - you should now see `SomeFile.cshtml.generated.cs` next to your `SomeFile.cshtml`, this new file will contain a class `SomeFile` that extends `RazorLight.TemplatePage<TModel>` and will be in the namespace of your project at the folder level your file was in
21+
3. Compile - you should now see `SomeFile.cshtml.cs` next to your `SomeFile.cshtml`, this new file will contain a class `SomeFile` that extends `RazorLight.TemplatePage<TModel>` and will be in the namespace of your project at the folder level your file was in
2222
4. Execute the following code to get a rendered result (note: you'll need to add a `using RazorRenderer;`): `new SomeFile().Render(model, viewBag or null)` - there is also an async variant
2323

2424
## Intellisense
@@ -28,3 +28,21 @@ For intellisense to work it's recommended you add the following to the top of yo
2828
```cshtml
2929
@inherits RazorLight.TemplatePage<MyModelType>
3030
```
31+
32+
## File Nesting
33+
34+
By default, your `.cshtml.cs` files will be nested under their `.cshtml` counterparts this using the [File Nesting feature in Visual Studio](https://docs.microsoft.com/en-us/visualstudio/ide/file-nesting-solution-explorer?view=vs-2019) if your project is classified as an ASP.NET Core project.
35+
36+
If you have a console app or class library you can trick it by ensuring your `.csproj` file starts with `<Project Sdk="Microsoft.NET.Sdk.Web">`.
37+
38+
Note: if you have a console app that means you'll need to add a `launchsettings.json` file in your `Properties` folder with something like this so that F5 still launches the app rather than IIS Express:
39+
40+
```json
41+
{
42+
"profiles": {
43+
"Test": {
44+
"commandName": "Project"
45+
}
46+
}
47+
}
48+
```
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"profiles": {
3+
"Test": {
4+
"commandName": "Project"
5+
}
6+
}
7+
}

Test/Test.csproj

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
@@ -7,10 +7,6 @@
77
<BuildPath>$(MSBuildThisFileDirectory)..\MSBuildRazorCompiler\bin\$(Configuration)\</BuildPath>
88
</PropertyGroup>
99

10-
<ItemGroup>
11-
<FrameworkReference Include="Microsoft.AspNetCore.App" />
12-
</ItemGroup>
13-
1410
<ItemGroup>
1511
<PackageReference Include="razorlight" Version="2.0.0-beta7" />
1612
</ItemGroup>

0 commit comments

Comments
 (0)