Skip to content

Commit

Permalink
Add ASP.NET 5 project to build script
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel15 committed Feb 28, 2015
1 parent 6a18a8f commit cfba7c4
Show file tree
Hide file tree
Showing 12 changed files with 165 additions and 33 deletions.
76 changes: 62 additions & 14 deletions build.proj
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,18 @@ of patent rights can be found in the PATENTS file in the same directory.
<Project ToolsVersion="4.0" DefaultTargets="Build;Test;Package" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Major>1</Major>
<Minor>3</Minor>
<Build>1</Build>
<Minor>4</Minor>
<Build>0</Build>
<Revision>0</Revision>
<DevNuGetServer>http://reactjs.net/packages/</DevNuGetServer>
<MSBuildCommunityTasksPath>$(MSBuildProjectDirectory)\tools\MSBuildTasks</MSBuildCommunityTasksPath>
<SolutionFile>src\React.sln</SolutionFile>
<PackageOutputDir>output</PackageOutputDir>

<!-- Only build ASP.NET 5 projects if on MSBuild 14+ (VS2015+) -->
<BuildAspNet5>false</BuildAspNet5>
<BuildAspNet5 Condition="$(VisualStudioVersion) == '14.0'">true</BuildAspNet5>
<SolutionFile>src\React.VS2015.sln</SolutionFile>
<SolutionFile Condition="$(BuildAspNet5) == 'false'">src\React.sln</SolutionFile>
</PropertyGroup>
<ItemGroup>
<PackageAssemblies Include="React" />
Expand All @@ -28,14 +33,12 @@ of patent rights can be found in the PATENTS file in the same directory.
<PackageAssemblies Include="React.MSBuild" />
<PackageAssemblies Include="React.JavaScriptEngine.VroomJs" />
<PackageAssemblies Include="React.JavaScriptEngine.ClearScriptV8" />
<PackageAssembliesAspNet5 Include="React.AspNet5" />
<AspNet5ProjectJson Include="src/**/project.json" />
</ItemGroup>

<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
<UsingTask
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll"
TaskName="TransformXml"
/>

<Import Project="src/React.tasks.proj" />

<Target Name="RestorePackages">
<Exec
WorkingDirectory="$(MSBuildProjectDirectory)"
Expand All @@ -47,27 +50,64 @@ of patent rights can be found in the PATENTS file in the same directory.
<GitVersion LocalPath="$(MSBuildProjectDirectory)">
<Output TaskParameter="CommitHash" PropertyName="Revision" />
</GitVersion>
<!--TODO: Only do this if a dev build -->
<Time Format="yyyyMMdd-HHmm">
<Output TaskParameter="FormattedTime" PropertyName="Date" />
</Time>
<!-- Prepend date to build version if a dev build-->
<PropertyGroup Condition="$(BuildType) == 'Release'">
<FullBuild>$(Build)</FullBuild>
</PropertyGroup>
<PropertyGroup Condition="$(BuildType) != 'Release'">
<Build>$(Build)-dev-$(Date)</Build>
<FullBuild>$(Build)-dev-$(Date)</FullBuild>
</PropertyGroup>
<!-- Set version for .csproj projects -->
<AssemblyInfo
CodeLanguage="CS"
OutputFile="src\SharedAssemblyVersionInfo.cs"
AssemblyVersion="$(Major).$(Minor)"
AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)"
AssemblyInformationalVersion="$(Major).$(Minor).$(Build)"
/>
AssemblyFileVersion="$(Major).$(Minor).$(FullBuild).$(Revision)"
AssemblyInformationalVersion="$(Major).$(Minor).$(FullBuild)"
/>
<!--
Set version for ASP.NET 5 projects. In theory K_BUILD_VERSION should work but it doesn't seem
to be functional yet :(. We work around this by physically writing the build number to the
project.json files. For development builds we write the full version number (including
build date) and reset it later so the dev build number isn't commited to the repo.
-->
<!--SetEnvironmentVariable
Condition="$(BuildAspNet5) == 'true'"
Name="K_BUILD_VERSION"
Value="$(Build)"
/-->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
Version="$(Major).$(Minor).$(FullBuild)"
/>
</Target>

<Target Name="Clean" BeforeTargets="Build">
<!--
ASP.NET 5 projects don't delete generated .nupkg files when cleaned or rebuilt, so we need to
do it here. See https://github.com/aspnet/XRE/issues/1301
-->
<ItemGroup>
<OldAspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/**/*.nupkg" />
</ItemGroup>
<Delete Files="@(OldAspNet5Packages)" />
</Target>

<Target Name="Build" DependsOnTargets="RestorePackages;UpdateVersion">
<MSBuild Projects="$(SolutionFile)" Targets="Rebuild" Properties="Configuration=Release;Platform=Any CPU;NoWarn=1607" />
</Target>

<Target Name="ResetAspNetVersion" AfterTargets="Build">
<!-- Resets the version number in ASP.NET project.json files so we don't commit -dev- version numbers -->
<UpdateAspNetProjectVersion
Files="@(AspNet5ProjectJson)"
Version="$(Major).$(Minor).$(Build)-*"
/>
</Target>

<Target Name="Test" DependsOnTargets="Build">
<ItemGroup>
<TestAssemblies Include="bin/ReleaseTests/**/React.Tests*.dll" />
Expand Down Expand Up @@ -98,6 +138,14 @@ of patent rights can be found in the PATENTS file in the same directory.
/>
</Target>

<Target Name="CopyAspNetPackages" AfterTargets="Package" Condition="$(BuildAspNet5) == 'true'">
<!-- Copy over ASP.NET 5 packages -->
<ItemGroup>
<AspNet5Packages Include="bin/%(PackageAssembliesAspNet5.Identity)/Release/*.nupkg" />
</ItemGroup>
<Copy SourceFiles="@(AspNet5Packages)" DestinationFolder="output" />
</Target>

<Target Name="Push">
<CallTarget Targets="PushDev" Condition="$(BuildType) != 'Release'" />
<CallTarget Targets="PushRelease" Condition="$(BuildType) == 'Release'" />
Expand Down
6 changes: 5 additions & 1 deletion dev-build-push.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Dev
)
pause
3 changes: 0 additions & 3 deletions dev-build-vs2015.bat

This file was deleted.

6 changes: 5 additions & 1 deletion dev-build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Dev
)
pause
6 changes: 5 additions & 1 deletion release-build-push.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /t:Package;Push /p:BuildType=Release
)
pause
7 changes: 6 additions & 1 deletion release-build.bat
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
@echo off
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
IF EXIST "%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" (
"%ProgramFiles(x86)%\MSBuild\14.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
) ELSE (
"%ProgramFiles(x86)%\MSBuild\12.0\Bin\MSBuild.exe" build.proj /p:BuildType=Release
)
pause
pause
2 changes: 1 addition & 1 deletion src/React.AspNet5/React.AspNet5.kproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<ProjectGuid>a7acdb56-5e43-40a6-92c9-2c52228e6074</ProjectGuid>
<RootNamespace>React.AspNet5</RootNamespace>
<BaseIntermediateOutputPath Condition="'$(BaseIntermediateOutputPath)'=='' ">..\artifacts\obj\$(MSBuildProjectName)</BaseIntermediateOutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\artifacts\bin\$(MSBuildProjectName)\</OutputPath>
<OutputPath Condition="'$(OutputPath)'=='' ">..\..\bin\$(MSBuildProjectName)\</OutputPath>
</PropertyGroup>
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<AssemblyName>React.AspNet5</AssemblyName>
Expand Down
22 changes: 14 additions & 8 deletions src/React.AspNet5/project.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
{
"version": "1.3.1-*",
"version": "1.4.0-*",
"configurations": {
"Debug": {
"compilationOptions": {
"define": ["DEBUG", "TRACE", "ASPNET5"]
"define": [ "DEBUG", "TRACE", "ASPNET5" ]
}
},
"Release": {
"compilationOptions": {
"define": ["RELEASE", "TRACE", "ASPNET5"],
"optimize": true
"define": [ "RELEASE", "TRACE", "ASPNET5" ],
"optimize": true,
"warningsAsErrors": true,
}
},
}
},
"dependencies": {
"Microsoft.Framework.DependencyInjection": "1.0.0.0-beta3",
Expand All @@ -20,8 +21,13 @@
"Microsoft.AspNet.StaticFiles": "1.0.0.0-beta3",
"React": ""
},

"frameworks": {
"aspnet50": {}
}
"aspnet50": { }
},

// NuGet info
"authors": [ "Daniel Lo Nigro" ],
"description": "ReactJS tools for ASP.NET 5, including ASP.NET MVC 6. Please refer to project site (http://reactjs.net/) for more details, usage examples and sample code",
"tags": [ "asp.net", "mvc", "asp", "javascript", "js", "react", "facebook", "reactjs", "vnext" ],
"projectUrl": "http://reactjs.net/"
}
2 changes: 1 addition & 1 deletion src/React.Sample.Mvc6/project.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
/* Click to learn more about project.json http://go.microsoft.com/fwlink/?LinkID=517074 */
"webroot": "wwwroot",
"version": "1.0.0-*",
"version": "1.4.0-*",
"dependencies": {
"Microsoft.AspNet.Mvc": "6.0.0.0-beta3",
"Microsoft.AspNet.Diagnostics": "1.0.0.0-beta3",
Expand Down
3 changes: 2 additions & 1 deletion src/React.VS2015.sln
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22512.0
VisualStudioVersion = 14.0.22609.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{F567B25C-E869-4C93-9C96-077761250F87}"
EndProject
Expand All @@ -15,6 +15,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Build", "Build", "{CB51F03F
..\build.proj = ..\build.proj
..\dev-build-push.bat = ..\dev-build-push.bat
..\dev-build.bat = ..\dev-build.bat
build\React.tasks.proj = build\React.tasks.proj
..\README.md = ..\README.md
..\release-build-push.bat = ..\release-build-push.bat
..\release-build.bat = ..\release-build.bat
Expand Down
63 changes: 63 additions & 0 deletions src/React.tasks.proj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (c) 2015, Facebook, Inc.
All rights reserved.
This source code is licensed under the BSD-style license found in the
LICENSE file in the root directory of this source tree. An additional grant
of patent rights can be found in the PATENTS file in the same directory.
-->
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildProjectDirectory)\tools\MSBuildTasks\MSBuild.Community.Tasks.Targets" />
<UsingTask
AssemblyFile="$(MSBuildExtensionsPath)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Web\Microsoft.Web.Publishing.Tasks.dll"
TaskName="TransformXml"
/>

<UsingTask
TaskName="SetEnvironmentVariable"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Name Required="true" />
<Value Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs"><![CDATA[
Log.LogError(Name + " = " + Value);
Environment.SetEnvironmentVariable(Name, Value);
]]></Code>
</Task>
</UsingTask>

<UsingTask
TaskName="UpdateAspNetProjectVersion"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<ParameterGroup>
<Files ParameterType="Microsoft.Build.Framework.ITaskItem[]" Required="true" />
<Version Required="true" />
</ParameterGroup>
<Task>
<Using Namespace="System" />
<Using Namespace="System.Text.RegularExpressions" />
<Code Type="Fragment" Language="cs"><![CDATA[
// This should be using a real JSON parser rather than regular expressions, but it will
// do for now.
var versionRegex = new Regex("\"version\": \"([^\"]+)\"");
foreach (var file in Files) {
var path = file.GetMetadata("FullPath");
var contents = File.ReadAllText(path);
var newContents = versionRegex.Replace(
contents,
string.Format("\"version\": \"{0}\"", Version)
);
File.WriteAllText(path, newContents);
Log.LogMessage("Updated version in {0}", path);
}
]]></Code>
</Task>
</UsingTask>
</Project>
2 changes: 1 addition & 1 deletion src/wrap/React/project.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.3.1-*",
"version": "1.4.0-*",
"frameworks": {
"net40": {
"wrappedProject": "../../React/React.csproj",
Expand Down

0 comments on commit cfba7c4

Please sign in to comment.