Skip to content

Commit c32cd86

Browse files
committed
NuGet package for MSBuild task
1 parent bb607d6 commit c32cd86

File tree

6 files changed

+115
-0
lines changed

6 files changed

+115
-0
lines changed

build.proj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ of patent rights can be found in the PATENTS file in the same directory.
2626
<PackageAssemblies Include="React.Web.Mvc3" />
2727
<PackageAssemblies Include="System.Web.Optimization.React" />
2828
<PackageAssemblies Include="Cassette.React" />
29+
<PackageAssemblies Include="React.MSBuild" />
2930
</ItemGroup>
3031

3132
<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" DefaultTargets="TransformJsx">
3+
<!-- ReactJS.NET - Transforms JSX to JavaScript -->
4+
<UsingTask AssemblyFile="$(OutputPath)\React.MSBuild.dll" TaskName="TransformJsx" />
5+
<Target Name="TransformJsx">
6+
<TransformJsx SourceDir="$(MSBuildProjectDirectory)" />
7+
</Target>
8+
</Project>

src/React.MSBuild/React.MSBuild.csproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<Name>React</Name>
6060
</ProjectReference>
6161
</ItemGroup>
62+
<ItemGroup>
63+
<None Include="Content\TransformJsx.proj" />
64+
<None Include="tools\install.ps1" />
65+
<None Include="React.MSBuild.nutrans" />
66+
<None Include="tools\uninstall.ps1" />
67+
</ItemGroup>
6268
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
6369
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
6470
Other similar extension points exist, see Microsoft.Common.targets.
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
Copyright (c) 2014, Facebook, Inc.
4+
All rights reserved.
5+
6+
This source code is licensed under the BSD-style license found in the
7+
LICENSE file in the root directory of this source tree. An additional grant
8+
of patent rights can be found in the PATENTS file in the same directory.
9+
-->
10+
<package
11+
xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
12+
xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
13+
<metadata>
14+
<id xdt:Transform="Replace">React.MSBuild</id>
15+
<title xdt:Transform="Insert">ReactJS.NET - JSX for MSBuild</title>
16+
<description xdt:Transform="Insert">Allows you to compile JSX to JavaScript via an MSBuild task</description>
17+
<tags xdt:Transform="Replace">asp.net mvc asp jquery javascript js react facebook reactjs msbuild</tags>
18+
</metadata>
19+
<files xdt:Transform="Insert">
20+
<file src="Content\TransformJsx.proj" target="Content\" />
21+
<file src="tools\install.ps1" target="tools\" />
22+
<file src="tools\uninstall.ps1" target="tools\" />
23+
</files>
24+
</package>

src/React.MSBuild/tools/install.ps1

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
function Resolve-ProjectName {
2+
param(
3+
[parameter(ValueFromPipelineByPropertyName = $true)]
4+
[string[]]$ProjectName
5+
)
6+
7+
if($ProjectName) {
8+
$projects = Get-Project $ProjectName
9+
}
10+
else {
11+
# All projects by default
12+
$projects = Get-Project
13+
}
14+
15+
$projects
16+
}
17+
18+
function Get-MSBuildProject {
19+
param(
20+
[parameter(ValueFromPipelineByPropertyName = $true)]
21+
[string[]]$ProjectName
22+
)
23+
Process {
24+
(Resolve-ProjectName $ProjectName) | % {
25+
$path = $_.FullName
26+
@([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($path))[0]
27+
}
28+
}
29+
}
30+
31+
$project = Get-Project
32+
$buildProject = Get-MSBuildProject
33+
$target = $buildProject.Xml.AddTarget("TransformJsx")
34+
$target.AfterTargets = "Build"
35+
$task = $target.AddTask("Exec")
36+
$task.SetParameter("Command", '"$(msbuildtoolspath)\msbuild.exe" $(ProjectDirectory)TransformJsx.proj /p:OutputPath=$(OutputPath) /nr:false')
37+
$project.Save()

src/React.MSBuild/tools/uninstall.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function Resolve-ProjectName {
2+
param(
3+
[parameter(ValueFromPipelineByPropertyName = $true)]
4+
[string[]]$ProjectName
5+
)
6+
7+
if($ProjectName) {
8+
$projects = Get-Project $ProjectName
9+
}
10+
else {
11+
# All projects by default
12+
$projects = Get-Project
13+
}
14+
15+
$projects
16+
}
17+
18+
function Get-MSBuildProject {
19+
param(
20+
[parameter(ValueFromPipelineByPropertyName = $true)]
21+
[string[]]$ProjectName
22+
)
23+
Process {
24+
(Resolve-ProjectName $ProjectName) | % {
25+
$path = $_.FullName
26+
@([Microsoft.Build.Evaluation.ProjectCollection]::GlobalProjectCollection.GetLoadedProjects($path))[0]
27+
}
28+
}
29+
}
30+
31+
$project = Get-Project
32+
$buildProject = Get-MSBuildProject
33+
34+
$existingImports = $buildProject.Xml.Targets | where {$_.Name -eq "TransformJsx"}
35+
foreach ($import in $existingImports) {
36+
$buildProject.Xml.RemoveChild($import)
37+
}
38+
39+
$project.Save()

0 commit comments

Comments
 (0)