Building Hello World Using MSBuild


Let s look at the files necessary to create a simple navigation-based Hello World application. Later I ll describe the purpose and use of each file in detail.

First, you need to define the Application object. You do this in a file typically called the application definition file . This HelloWorldApplication.xaml file defines my Application object.

HelloWorldApplication.xaml
start example
 <NavigationApplication xmlns="http://schemas.microsoft.com/2003/xaml" 
StartupUri="HelloWorld.xaml" />
end example
 

This definition says, For my Application object, I want to use an instance of the MSAvalon.Windows.Navigation.NavigationApplication class. On startup, the application should navigate to and display the user interface (UI) defined in the HelloWorld.xaml file.

Here are the contents of the HelloWorld.xaml file. It s a slightly more interesting version of the previous Hello World example in Chapter 1.

HelloWorld.xaml
start example
 <Border xmlns="http://schemas.microsoft.com/2003/xaml"> 
<FlowPanel>
<SimpleText Foreground="DarkRed" FontSize="14">Hello World!</SimpleText>
</FlowPanel>
</Border>
end example
 

Now that I have all the code for my simple Hello World application, I need a project file that defines how to build my application. Here s my HelloWorld.proj file.

HelloWorld.proj
start example
 <Project DefaultTargets="Build"> 
<PropertyGroup>
<Property Language="C#" />
<Property DefaultClrNameSpace="IntroLonghorn" />
<Property TargetName="HelloWorld" />
</PropertyGroup>

<!--Imports the target which contains all the common targets-->
<Import Project="$(LAPI)\WindowsApplication.target" />

<ItemGroup>
<!-- Application markup -->
<Item Type="ApplicationDefinition" Include="HelloWorldApplication.xaml" />

<!-- Compiled Xaml Files list -->
<Item Type="Pages" Include="HelloWorld.xaml"/>
</ItemGroup>
</Project>
end example
 

Put these three files in a directory. Open a Longhorn SDK command prompt, navigate to the directory containing your files, and run MSBuild. It will compile your program into an executable.

We ll examine the contents of the application definition file later in this chapter. In Chapter 3, I describe in detail many of the Extensible Application Markup Language (XAML) elements you can use to define a UI. Before we look at the project file in more depth, let s review some MSBuild terminology.




Introducing Microsoft WinFX
Introducing WinFX(TM) The Application Programming Interface for the Next Generation of Microsoft Windows Code Name Longhorn (Pro Developer)
ISBN: 0735620857
EAN: 2147483647
Year: 2004
Pages: 83
Authors: Brent Rector

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net