Skip to content

Commit ab6bb00

Browse files
committed
Added MSBuild task generation infrastructure as per https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/
1 parent d866b9c commit ab6bb00

12 files changed

+61
-142
lines changed

.gitignore

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

MSBuildRazorCompiler.sln

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test", "Test\Test.csproj",
99
EndProject
1010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RazorRenderer", "RazorRenderer\RazorRenderer.csproj", "{24E7F601-6B61-4C07-95A8-F52A6937BF3A}"
1111
EndProject
12+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{A2313EC1-CA69-4120-9B79-D9C7EB1ABACA}"
13+
ProjectSection(SolutionItems) = preProject
14+
.gitattributes = .gitattributes
15+
.gitignore = .gitignore
16+
build.ps1 = build.ps1
17+
EndProjectSection
18+
EndProject
1219
Global
1320
GlobalSection(SolutionConfigurationPlatforms) = preSolution
1421
Debug|Any CPU = Debug|Any CPU
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!-- https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/ -->
2+
<Project>
3+
<PropertyGroup>
4+
<MSBuildRazorCompilerExe>dotnet "$(MSBuildThisFileDirectory)/netcoreapp3.1/MSBuildRazorCompiler.dll"</MSBuildRazorCompilerExe>
5+
<MsBuildRazorCompilerPath>$(MSBuildProjectDirectory)</MsBuildRazorCompilerPath>
6+
<MsBuildRazorCompilerRootNamespace>$(RootNamespace)</MsBuildRazorCompilerRootNamespace>
7+
</PropertyGroup>
8+
9+
<Target Name="CompileRazorFiles" BeforeTargets="Build">
10+
<Exec Command="$(MSBuildRazorCompilerExe) ""$(MsBuildRazorCompilerPath)"" $(RootNamespace)" />
11+
</Target>
12+
</Project>

MSBuildRazorCompiler/MSBuildRazorCompiler.csproj

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,23 @@
99
<PackageReference Include="RazorLight" Version="2.0.0-beta7" />
1010
</ItemGroup>
1111

12+
<!-- Ensure RazorRenderer builds first so we can grab it when creating our nuget package -->
13+
<ItemGroup>
14+
<ProjectReference Include="..\RazorRenderer\RazorRenderer.csproj" />
15+
</ItemGroup>
16+
17+
<!-- Pack settings -->
18+
<PropertyGroup>
19+
<NoPackageAnalysis>true</NoPackageAnalysis>
20+
<NuspecFile>MsBuildRazorCompiler.nuspec</NuspecFile>
21+
<IntermediatePackDir>$(MSBuildProjectDirectory)/bin/$(Configuration)/publish/</IntermediatePackDir>
22+
<PublishDir>$(IntermediatePackDir)$(TargetFramework)/</PublishDir>
23+
<NuspecProperties>publishDir=$([MSBuild]::NormalizeDirectory($(IntermediatePackDir)))</NuspecProperties>
24+
</PropertyGroup>
25+
26+
<!-- Executes /t:Publish for all target frameworks before packing-->
27+
<Target Name="PublishAll" BeforeTargets="GenerateNuspec">
28+
<MSBuild Projects="$(MSBuildProjectFullPath)" Targets="Publish" />
29+
</Target>
30+
1231
</Project>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<!-- https://natemcmaster.com/blog/2017/11/11/build-tools-in-nuget/ -->
2+
<Project>
3+
<Import Project="$(MSBuildThisFileDirectory)/../../tools/CompileRazorFiles.targets" />
4+
</Project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>MSBuildRazorCompiler</id>
5+
<version>1.0.0</version>
6+
<authors>Robert Moore, Matt Davies, MRCollective</authors>
7+
<description>MSBuild target to statically compile .cshtml files on build of your project and then provide the code to render them at runtime.</description>
8+
</metadata>
9+
<files>
10+
<file src="..\RazorRenderer\bin\Release\netcoreapp3.1\*.*" target="lib/netcoreapp3.1/" />
11+
<file src="MSBuildRazorCompiler.targets" target="build/netcoreapp3.1/MSBuildRazorCompiler.targets" />
12+
13+
<file src="CompileRazorFiles.targets" target="tools/" />
14+
<file src="$publishdir$\netcoreapp3.1\**\*" target="tools/netcoreapp3.1/" />
15+
</files>
16+
</package>

Test/ModelType.cshtml.generated.cs

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

Test/Subfolder/SubSubFolder/date.cshtml.generated.cs

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

Test/Subfolder/date.cshtml.generated.cs

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

Test/Test.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,4 @@
1010
<FrameworkReference Include="Microsoft.AspNetCore.App" />
1111
</ItemGroup>
1212

13-
<ItemGroup>
14-
<ProjectReference Include="..\RazorRenderer\RazorRenderer.csproj" />
15-
</ItemGroup>
16-
1713
</Project>

0 commit comments

Comments
 (0)