It took a while, but we have finally gotten Peachpie up to speed with the latest development over at Microsoft. Project.json is now history and MSBuild has taken over as the go-to build platform of Microsoft and Visual Studio. Besides this major change, we are also happy to announce that Peachpie finally supports .NET Core 1.1.
Quick trip down memory lane
If you’ve never heard of project.json, don’t worry – this project file format is now completely deprecated. However, for completions’ sake, let’s quickly recap what it was and why it was useful. At the time, project.json replaced the legacy csproj format to specify project information, such as metadata, dependencies or compilation information. It received fairly positive feedback due to its easy readability, autocomplete for dependencies and simplified structure. As soon as the first larger applications started being developed in .NET Core, however, concerns began to surface that project.json was not supported within MSBuild, which eventually lead to the decision to replace it with the backward compatible, MSBuild ready, csproj again.
The json-like format of project files was already completely removed in all the latest releases of .NET Core. The entire .NET platform targets now run on the xml-like project system (again) called MSBuild – the next generation build engine from Microsoft unveiled at the 2003 Microsoft Professional Developers Conference.
In this blog post, we would like to announce that Peachpie itself is now migrated to Visual Studio 2017 and MSBuild. Furthermore, PHP projects for Peachpie use the standard msbuild file now, of course referencing the Peachpie SDK from a NuGet package.
As a consequence of building Peachpie from the sources (github.com/iolevel/peachpie) you will need VS 2017 now, or at least your favorite shell and the dotnet SDK (1.0.1 or newer). With this upgrade, we could instantly feel that the development has sped up, as the new Visual Studio has the latest version of Roslyn integrated.
Sample project file
The brand new Visual Studio 2017 offers a fantastic development environment for Peachpie projects. To build a PHP project, you also need to create project file – in msbuild format – with the
.msbuildproj extension. Below you can find a sample msbuild file, which you can also find in our samples repository:
Sample msbuild configuration that utilizes Peachpie to compile PHP files:
<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp1.1</TargetFramework> </PropertyGroup> <ItemGroup> <Compile Include="**/*.php" /> </ItemGroup> <ItemGroup> <DotNetCliToolReference Include="Peachpie.Compiler.Tools" Version="0.7.0-*" /> <PackageReference Include="Peachpie.NET.Sdk" Version="0.7.0-*" PrivateAssets="Build" /> </ItemGroup> <!-- A temporary solution, import C# Visual Studio design time targets in order to be able to load the project in Visual Studio --> <PropertyGroup> <CSharpDesignTimeTargetsPath Condition="'$(CSharpDesignTimeTargetsPath)'==''">$(MSBuildExtensionsPath)MicrosoftVisualStudioManagedMicrosoft.CSharp.DesignTime.targets</CSharpDesignTimeTargetsPath> </PropertyGroup> <Import Project="$(CSharpDesignTimeTargetsPath)" Condition="'$(CSharpDesignTimeTargetsPath)' != '' and Exists('$(CSharpDesignTimeTargetsPath)')" /> </Project>
This file tells the
msbuild.exe utility to compile all the
*.php files using Peachpie compiler (see line 8). Run
dotnet restore or
msbuild /t:restore before to download all the dependencies, including the Peachpie SDK and Peachpie runtime. Then you can build and run the project.
The Peachpie SDK (line 13) is a NuGet package containing build targets that are automatically imported by MSBuild. The imported targets define the
CoreCompile task that invokes Peachpie Compiler (referenced as a tool package on line 12). The SDK package also references the
Peachpie.App package, which is propagated as a reference to the compiled project.
Peachpie.App contains the complete Peachpie runtime and the necessary libraries ensuring the running of the compiled project. The sample
msbuildproj also specifies the output type
exe (line 3), so our compiled project will have an entry point and become executable. Line 4 denotes that we are targeting .NET Core 1.1. We can specify
net46 or anything compatible with minimum Peachpie dependencies.
Sample index.php file:
The process of getting the project running on your favorite shell remains the same:
Which is technically the same as:
msbuild /t:restore project.msbuildproj
msbuild /t:build project.msbuildproj
.NET Core 1.1 support
Many of you noted that Peachpie was not working with .NET Core 1.1 for a while. This, too, is now history, as the build subsystem now fully supports .NET Core 1.1.
The build subsystem works well with all the target frameworks and runtimes. Previously we had some issues with .NET Core 1.1, which now works out of the box. Just build and run the project under anything that supports
netstandard1.6 (so .NET Core 1.0.1 and newer) or
net46 (full .NET Framework 4.6 or newer). As a side note, we will in fact add support for
netstandard1.5 soon, for what should be quite the interesting announcement, as well.
The new project format brings a lot of new possibilities. It is compatible with tons of existing tools (Xamarin, VSCode, VS 2017) and can be customized in industry standard ways, like writing your own targets or even better – using existing targets. Definitely stay tuned for future updates, since we will make serious use of the new MSBuild soon.