Share via


MarkupCompilePass1 task

The MarkupCompilePass1 task converts non-localizable XAML project files to compiled binary format.

Task parameters

Parameter Description
AllGeneratedFiles Optional ITaskItem[] output parameter.

Contains a complete list of files that are generated by the MarkupCompilePass1 task.
AlwaysCompileMarkupFilesInSeparateDomain Optional Boolean parameter.

Specifies whether to run the task in a separate AppDomain. If this parameter returns false, the task runs in the same AppDomain as MSBuild and it runs faster. If the parameter returns true, the task runs in a second AppDomain that is isolated from MSBuild and runs slower.
ApplicationMarkup Optional ITaskItem[] parameter.

Specifies the name of the application definition XAML file.
AssembliesGeneratedDuringBuild Optional String[] parameter.

Specifies references to assemblies that change during the build process. For example, a Visual Studio solution may contain one project that references the compiled output of another project. In this case, the compiled output of the second project can be added to the AssembliesGeneratedDuringBuild parameter.

Note: The AssembliesGeneratedDuringBuild parameter must contain references to the complete set of assemblies that are generated by a build solution.
AssemblyName Required string parameter.

Specifies the short name of the assembly that is generated for a project. For example, if a project is generating a Windows executable whose name is WinExeAssembly.exe, the AssemblyName parameter has a value of WinExeAssembly.
AssemblyPublicKeyToken Optional String parameter.

Specifies the public key token for the assembly.
AssemblyVersion Optional String parameter.

Specifies the version number of the assembly.
ContentFiles Optional ITaskItem[] parameter.

Specifies the list of loose content files.
DefineConstants Optional String parameter.

Specifies that the current value of DefineConstants, is kept. which affects target assembly generation; if this parameter is changed, the public API in the target assembly may be changed and the compilation of XAML files that reference local types may be affected.
ExtraBuildControlFiles Optional ITaskItem[] parameter.

Specifies a list of files that control whether a rebuild is triggered when the MarkupCompilePass1 task reruns; a rebuild is triggered if one of these files changes.
GeneratedBamlFiles Optional ITaskItem[] output parameter.

Contains the list of generated files in XAML binary format.
GeneratedCodeFiles Optional ITaskItem[] output parameter.

Contains the list of generated managed code files.
GeneratedLocalizationFiles Optional ITaskItem[] output parameter.

Contains the list of localization files that were generated for each localizable XAML file.
HostInBrowser Optional String parameter.

Specifies whether the generated assembly is a XAML Browser Application (XBAP). The valid options are true and false. If true, code is generated to support browser hosting.
KnownReferencePaths Optional String[] parameter.

Specifies references to assemblies that do not change during the build process. Includes assemblies that are located in the global assembly cache (GAC), in a .NET installation directory, and so on.
Language Required String parameter.

Specifies the managed language that the compiler supports. The valid options are C#, VB, JScript, and C++.
LanguageSourceExtension Optional String parameter.

Specifies the extension that is appended to the extension of the generated managed code file:

<Filename>.g<LanguageSourceExtension>

If the LanguageSourceExtension parameter is not set with a specific value, the default source file name extension for a language is used: .vb for Visual Basic, .csharp for C#.
LocalizationDirectivesToLocFile Optional String parameter.

Specifies how to generate localization information for each source XAML file. The valid options are None, CommentsOnly, and All.
OutputPath Required String parameter.

Specifies the directory in which the generated managed code files and XAML binary format files are generated.
OutputType Required String parameter.

Specifies the type of assembly that is generated by a project. The valid options are winexe, exe, library, and netmodule.
PageMarkup Optional ITaskItem[] parameter.

Specifies a list of XAML files to process.
References Optional ITaskItem[] parameter.

Specifies the list of references from files to assemblies that contain the types that are used in the XAML files.
RequirePass2ForMainAssembly Optional Boolean output parameter.

Indicates whether the project contains non-localizable XAML files that reference local types that are embedded into the main assembly.
RequirePass2ForSatelliteAssembly Optional Boolean output parameter.

Indicates whether the project contains localizable XAML files that reference local types that are embedded in the main assembly.
RootNamespace Optional String parameter.

Specifies the root namespace for classes that are inside the project. RootNamespace is also used as the default namespace of a generated managed code file when the corresponding XAML file does not include the x:Class attribute.
SourceCodeFiles Optional ITaskItem[] parameter.

Specifies the list of code files for the current project. The list does not include generated language-specific managed code files.
UICulture Optional String parameter.

Specifies the satellite assembly for the UI culture in which the generated XAML binary format files are embedded. If UICulture is not set, the generated XAML binary format files are embedded in the main assembly.
XAMLDebuggingInformation Optional Boolean parameter.

When true, diagnostic information is generated and included in the compiled XAML in order to aid debugging.

Remarks

The MarkupCompilePass1 task typically compiles XAML into binary format and generates code files. If a XAML file contains references to types that are defined in the same project, its compilation to binary format is deferred by MarkupCompilePass1 to a second markup compilation pass (MarkupCompilePass2). Such files must have their compilation deferred because they must wait until the referenced locally-defined types are compiled. However, if a XAML file has an x:Class attribute, MarkupCompilePass1 generates the language-specific code file for it.

A XAML file is localizable if it contains elements that use the x:Uid attribute:

<Page x:Class="WPFMSBuildSample.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:Uid="Page1Uid"
    >
  ...
</Page>

A XAML file references a locally-defined type when it declares an XML namespace that uses the clr-namespace value to refer to a namespace in the current project:

<Page x:Class="WPFMSBuildSample.Page1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:localNamespace="clr-namespace:WPFMSBuildSample"
    >
    <Grid>
      <Grid.Resources>
        <localNameSpace:LocalType x:Key="localType" />
      </Grid.Resources>
      ...
    </Grid>
</Page>

If any XAML file is localizable, or references a locally-defined type, a second markup compilation pass is required, which requires running the GenerateTemporaryTargetAssembly and then the MarkupCompilePass2.

Example

The following example shows how to convert three Page XAML files to binary format files. Page1 contains a reference to a type, Class1, which is in the root namespace of the project and therefore, is not converted to binary format files in this markup compile pass. Instead, the GenerateTemporaryTargetAssembly is executed and is followed by the MarkupCompilePass2.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <UsingTask
    TaskName="Microsoft.Build.Tasks.Windows.MarkupCompilePass1"
    AssemblyFile="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationBuildTasks.dll" />
  <Target Name="MarkupCompilePass1Task">
    <MarkupCompilePass1
      AssemblyName="WPFMSBuildSample"
      Language="C#"
      OutputType="WinExe"
      OutputPath="obj\Debug\"
      ApplicationMarkup="App.xaml"
      PageMarkup="Page1.xaml;Page2.xaml;Page3.xaml"
      SourceCodeFiles="Class1.cs"
      References="c:\windows\Microsoft.net\Framework\v2.0.50727\System.dll;C:\Program Files\Reference Assemblies\Microsoft\WinFx\v3.0\PresentationCore.dll;C:\Program Files\Reference Assemblies\Microsoft\WinFx\v3.0\PresentationFramework.dll;C:\Program Files\Reference Assemblies\Microsoft\WinFx\v3.0\WindowsBase.dll" />
  </Target>
</Project>

See also