First MSBuild Project File - Hello.proj

A tutorial example is provided to a very simple MSBuild project file, Hello.proj, to compile a C# source file, Hello.cs.

To learn how to use MSBuild, let's start with a very simple project file, Hello.proj:

<!-- Hello.proj
// Copyright (c) 2015 by Dr. Herong Yang,
<Project xmlns="">
    <Compile Include="Hello.cs" />
  <Target Name="Build">
    <Csc Sources="@(Compile)"/>  

This project file is easy to understand:

Running MSBuild with the above project file is easy too:

C:\herong>set "NET=\windows\Microsoft.NET\Framework\v4.0.30319"

C:\herong>%NET%\msbuild Hello.proj
Microsoft (R) Build Engine version 4.6.1055.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 10:53:01 PM.
Project "C:\herong\Hello.proj" on node 1 (Build target(s)).
  C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:Hello.exe
Done Building Project "C:\herong\Hello.proj" (Build target(s)).

Build succeeded.
    0 Warning(s)
    0 Error(s)
Hello world!

Cool. The MSBuild tool did a good job to compile my Hello.cs C# source file. But it used an older version of "csc" from .NET Framework 2.0 SDK. We will modify the project file to fix the issue in the next tutorial.

Last update: 2015.

Table of Contents

 About This Book

 Introduction of C# (C Sharp)

 Data Type and Variables

 Logical Expressions and Conditional Statements

 Arrays and Loop Statements

 Data Type Features

 Floating-Point Data Types

 Passing Parameters to Methods

 Execution Environment Class

 Visual C# 2010 Express Edition

 Class Features

 C# Compiler and Intermediate Language

 Compiling C# Source Code Files

MSBuild - Microsoft Build Engine

 What Is MSBuild?

First MSBuild Project File - Hello.proj

 Using MSBuild with Multiple Source Files

 Memory Usages of Processes

 Multithreading in C#

 Async Feature from C# 5

 System.IO.FileInfo Class

 System.Diagnostics.FileVersionInfo Class

 WPF - Windows Presentation Foundation

 Partial Classes and Partial Methods

 Outdated Tutorials


 PDF Printing Version