GenerateTemporaryTargetAssembly Task
The GenerateTemporaryTargetAssembly task generates an assembly if at least one Extensible Application Markup Language (XAML) page in a project references a type that is declared locally in that project. The generated assembly is removed after the build process is completed, or if the build process fails.
Task Parameters
Parameter |
Description |
---|---|
AssemblyName |
Required String parameter. Specifies the short name of the assembly that is generated for a project and is also the name of the target assembly that is temporarily generated. For example, if a project generates a Windows executable whose name is WinExeAssembly.exe, the AssemblyName parameter has a value of WinExeAssembly. |
CompileTargetName |
Required String parameter. Specifies the name of the Microsoft build engine (MSBuild) target that is used to generate assemblies from source code files. The typical value for CompileTargetName is CoreCompile. |
CompileTypeName |
Required String parameter. Specifies the type of compilation that is performed by the target that is specified by the CompileTargetName parameter. For the CoreCompile target, this value is Compile. |
CurrentProject |
Required String parameter. Specifies the full path of the MSBuild project file for the project that requires a temporary target assembly. |
GeneratedCodeFiles |
Optional ITaskItem[] parameter. Specifies the list of language-specific managed code files that were generated by the MarkupCompilePass1 Task task. |
IntermediateOutputPath |
Required String parameter. Specifies the directory that the temporary target assembly is generated to. |
MSBuildBinPath |
Required String parameter. Specifies the location of MSBuild.exe, which is required to compile the temporary target assembly. |
ReferencePath |
Optional ITaskItem[] parameter. Specifies a list of assemblies, by path and file name, that are referenced by the types that are compiled into the temporary target assembly. |
ReferencePathTypeName |
Required String parameter. Specifies the parameter that is used by the compilation target (CompileTargetName) parameter that specifies the list of assembly references (ReferencePath). The appropriate value is ReferencePath. |
Remarks
The first markup compilation pass, which is run by the MarkupCompilePass1 Task, compiles XAML files to binary format. Consequently, the compiler needs a list of the referenced assemblies that contain the types that are used by the XAML files. However, if a XAML file uses a type that is defined in the same project, a corresponding assembly for that project is not created until the project is built. Therefore, an assembly reference cannot be provided during the first markup compilation pass.
Instead, MarkupCompilePass1 defers the conversion of XAML files that contain references to types in the same project to a second markup compilation pass, which is executed by the MarkupCompilePass2 Task. Before MarkupCompilePass2 is executed, a temporary assembly is generated. This assembly contains the types that are used by the XAML files whose markup compilation pass was deferred. A reference to the generated assembly is provided to MarkupCompilePass2 when it runs to allow the deferred compilation XAML files to be converted to binary format.
Example
The following example generates a temporary assembly because Page1.xaml contains a reference to a type that is in the same project.
<Project xmlns="https://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="Microsoft.Build.Tasks.Windows.GenerateTemporaryTargetAssembly"
AssemblyFile="C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationBuildTasks.dll" />
<Target Name="GenerateTemporaryTargetAssemblyTask">
<GenerateTemporaryTargetAssembly
AssemblyName="WPFMSBuildSample"
CompileTargetName="CoreCompile"
CompileTypeName="Compile"
CurrentProject="FullBuild.proj"
GeneratedCodeFiles="obj\debug\app.g.cs;obj\debug\Page1.g.cs;obj\debug\Page2.g.cs"
ReferencePath="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"
IntermediateOutputPath=".\obj\debug\"
MSBuildBinPath="$(MSBuildBinPath)"
ReferencePathTypeName="ReferencePath"/>
</Target>
</Project>
See Also
Concepts
Building a WPF Application (WPF)
Windows Presentation Foundation XAML Browser Applications Overview
Other Resources
Windows Presentation Foundation MSBuild Reference