Building HelloWorld from the command line with msbuild

I know I have blogged previously about building with msbuild. Here is a simplified sample that can get you started with using msbuild as your build tool.
 
There are 3 files involved, all located in the same directory: build.bat (batch file to execute the build process), build.targets (the targets file used by msbuild), and HelloWorld.cs (the source code being built into the executable).
 
build.bat
@echo off
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727msbuild build.targets
 
You will, obviously, have to adjust the path the msbuild in build.bat if it is not installed in its default location.
 
build.targets
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
 <Target Name="Build">
      <Csc Sources="HelloWorld.cs" OutputAssembly="hello.exe"/>
 </Target>
</Project>
 
HelloWorld.cs
using System;
namespace Hello {
    public class World {
        [STAThread]
        public static void Main(string[] args) {
                Console.WriteLine("Hello World!");
                Console.Read();
        }
    }
}
 
The output creates hello.exe in the same folder as the code.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s