Skip to content

Project file reference#

MSBuild is the build system for .NET and Visual Studio. The MSBuild project file is an XML file describing the build process and more.

Sample Project File#

<Project Sdk="Peachpie.NET.Sdk/0.9.12">
  <PropertyGroup>
    <OutputType>library</OutputType>
    <TargetFramework>netstandard2.0</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Compile Include="**/*.php" />
  </ItemGroup>

</Project>

The sample project file above is supposed to be saved as your-project-name.msbuildproj. This particular example includes all the .php files into the compilation, uses the PeachPie compiler and targets class library projects. See the section Output Type below on how to target different project types. The project can be opened in Visual Studio 2017, Visual Studio Code, other IDEs or used from your favorite shell to build or run the project.

Note

Peachpie.NET.Sdk is downloaded from a NuGet feed. Visual Studio resolves the Sdk automatically since 15.6.

Build the project using an IDE or the command below:

dotnet build

Additional Properties#

OutputType#

The OutputType property specifies whether to output an executable (.exe) or a library (.dll). The possible values are:

  • library
  • exe - in combination with <TargetFramework>netcoreapp2.0</TargetFramework> or higher.
  • winexe
  • module

LangVersion#

The LangVersion property specifies the version of the PHP semantic. This allows you to treat built-in types with respect to the PHP version or to enable language constructs (like &new) that have been removed from the latest versions of PHP.

<LangVersion>5.4</LangVersion>

The options are 5.4, 5.5, 5.6, 7.0, 7.1, 7.2 etc.

This option affects the source code syntax and the types used in type hints. The following code has a different semantic according to the LangVersion value:

<?php
function foo(int $i, object $o, callable $c)
{
  // $i is either long or class `int`
  // $o is either an object or class `object`
}

ShortOpenTag#

The short open tag syntax (<?) is disabled by default. To enable it, set the ShortOpenTag property to true.

<ShortOpenTag>true</ShortOpenTag>

NoWarn#

Disables specific warning messages. The warnings are identified by their ID (e.g. PHP5006) and can be separated by a comma or a space.

<NoWarn>PHP5006,PHP0125</NoWarn>
The sample above disables the reporting of a call of an undefined function and declaring a mandatory parameter behind an optional parameter.

GenerateDocumentationFile#

Enables or disables the build of an .xml file with the XMLDoc generated from the source files' PHPDoc. The default value is false in order not to generate the XML documentation file.

<GenerateDocumentationFile>true</GenerateDocumentationFile>

enabling this option is recommended

In case the project containing the XML documentation is referenced by a C# project, the IDE's IntelliSense will display additional text information collected from the XMLDoc file.

Enaling this property also sets following properties if not specified else:

  • DocumentationFile
  • PublishDocumentationFile = true

PeachpieVersion#

The property is set by Sdk to the current version of Peachpie. It can be used in project files to refer to the Peachpie version being used. The value of the property can be changed in order to use a different Peachpie runtime and compiler for the project.

PhpDocTypes#

This property allows strongly typing PHP properties, functions or function parameters using regular PHPDoc comments. This is useful for keeping a backward compatibility with PHP 5 and to strongly type PHP properties.

<PhpDocTypes>FieldTypes</PhpDocTypes>

Possible values are None, FieldTypes, ParameterTypes, ReturnTypes or All or their combination using a vertical bar |. The default is None. In case there is a PHP type hint, then the PHPDoc type is ignored.

Example

The result of setting PhpDocTypes to FieldTypes and compilation of the following PHP source code

<?php
class A {
  /** @var array */
  var $a_property;
  /** @var int */
  var $integer_property;
}
is a .NET assembly containing an equivalent to the following C# code:
public class A {
  public PhpArray a_property;
  public long integer_property;
}

Warning

Be careful when enabling this option. Typed values won't persist a PHP reference.

StartupObject#

Specifies the function, method or file representing the application's main routine.

<OutputType>exe</OutputType>
<StartupObject>main.php</StartupObject>

The value can be set in one of the following formats:

  • filename.php - startup object as a file.
  • function_name - startup object as a global function.
  • class_name - lookups for a static method Main on given class as the startup object.
  • class_name::method_name - lookups for a method.

If the property is not specified, a script file that happens to be compiled first is used as the application's startup object.

Common snippets#

Create NuGet package#

The build system can automatically create a NuGet package. To create a NuGet package (.nupkg), insert the following snippet into the project file:

<PropertyGroup>
  <VersionPrefix>1.2.3</VersionPrefix>
  <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>

Sign with a Strong Name#

To provide a unique identity of the compiled assembly, sign the assembly with a strong name using a private key. Signing the assembly during the build process using your private key can be achieved using the following snippet:

<PropertyGroup>
  <!-- signing -->
  <AssemblyOriginatorKeyFile>my-key.snk</AssemblyOriginatorKeyFile>
  <SignAssembly>true</SignAssembly>
  <PublicSign Condition="'$(OS)' != 'Windows_NT'">true</PublicSign>
</PropertyGroup>