C# Tutorials - Herong's Tutorial Examples - v3.32, by Herong Yang
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) 2016 HerongYang.com. All Rights Reserved. --> <Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup> <Compile Include="Hello.cs" /> </ItemGroup> <Target Name="Build"> <Csc Sources="@(Compile)"/> </Target> </Project>
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)). Build: C:\Windows\Microsoft.NET\Framework\v2.0.50727\Csc.exe /out:Hello.exe Hello.cs Done Building Project "C:\herong\Hello.proj" (Build target(s)). Build succeeded. 0 Warning(s) 0 Error(s) C:\herong>Hello.exe 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.
Table of Contents
Logical Expressions and Conditional Statements
Visual C# 2010 Express Edition
C# Compiler and Intermediate Language
Compiling C# Source Code Files
►MSBuild - Microsoft Build Engine
►First MSBuild Project File - Hello.proj
Using MSBuild with Multiple Source Files
System.Diagnostics.FileVersionInfo Class
WPF - Windows Presentation Foundation