Follow the steps below to build a WPF application using MSBuild.
App.xaml
<Application x:Class=”WpfApplicationHelloWorld.App”
xmlns=”http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x=”http://schemas.microsoft.com/winfx/2006/xaml”
StartupUri=”MainWindow.xaml”>
<Application.Resources>
</Application.Resources>
</Application>
App.xaml.cs
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Windows;
namespace WpfApplicationHelloWorld
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
MainWindow.xaml
<Window x:Class="WpfApplicationHelloWorld.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid Background="IndianRed">
<Label Height="28" Margin="77,28,81,0" Name="lblHello"
VerticalAlignment="Top" Opacity="0.5"
Background="SlateGray" Foreground="White">
Label</Label>
<Button Height="23" Margin="77,66,126,0" Name="btnHello"
VerticalAlignment="Top" Click="btnHello_Click"
Opacity="0.5">Say Hello</Button>
</Grid>
</Window>
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.IO;
namespace WpfApplicationHelloWorld
{
///
/// Interaction logic for MainWindow.xaml
///
public partial class MainWindow : Window
{
private void btnHello_Click(object sender, RoutedEventArgs e)
{
lblHello.Content = "Hello WPF!";
}
}
}
WpfApplicationHelloWorld.csproj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003" > <PropertyGroup> <AssemblyName>WPFApplicationHelloWorld</AssemblyName> <OutputType>winexe</OutputType> </PropertyGroup> <ItemGroup> <Reference Include="System" /> <Reference Include="WindowsBase" /> <Reference Include="PresentationCore" /> <Reference Include="PresentationFramework" /> <Reference Include="System.Data" /> <Reference Include="System.Linq" /> </ItemGroup> <ItemGroup> <ApplicationDefinition Include="App.xaml" /> <Compile Include="App.xaml.cs" /> <Page Include="MainWindow.xaml" /> <Compile Include="MainWindow.xaml.cs" /> </ItemGroup> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.WinFX.targets" /> </Project>
Issue the MSBuild command, at the command-line.