2012年12月20日木曜日

Compiling WPF

Several tips in compiling C# WPF files in command console.
1. If references are not setup in environment,
you have to refer to the assemblies in default directory:
C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\
2. Compile options /target:winexe is needed if you do not
want a console window appear behind your window.

Example:

// win.cs
using System.Windows;
using System.Windows.Controls;

public class MyClass:Window
{
 public MyClass()
 {
  this.Title = "Nat";
  this.Width = 300;
  this.Height= 200;
 }
}

// app.cs 
using System;
using System.Windows;
public class MyApp : Application
{
 [STAThread]
 
 static void Main()
 {
  MyApp app = new MyApp();
  app.Startup += app.Fireup;
  app.Run();
 }

 void Fireup(object sender, StartupEventArgs args)
 {
  MyClass wm = new MyClass();
  wm.Show();
 }
}

To compile, Compile.bat
csc /target:winexe app.cs win.cs /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationFrameWork.dll" /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\PresentationCore.dll" /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\WindowsBase.dll"

0 件のコメント:

コメントを投稿