SushiHangover

PowerShell, Learn it or Perish ;-)

master nix
Gitter

C# AppleScript calls with functions, arguments and results

Posted a new C# library to Github to allow the calling of AppleScript by function name, passing in arguments and receiving a return value.

Sushi.AppleScript

https://github.com/sushihangover/Sushi.AppleScript

The C# library allows you to execute AppleScript code that originates from a file or string and:

  • Call function by name (Optional)
  • Pass multiple arguments to a function (Optional)
  • Execution success or failure
  • Return results from the function call

Build:

cd Sushi.AppleScript.Native
xcodebuild
cd -
xbuild Sushi.AppleScript.sln

Test:

Mono’s supplied nunit-console:

MONO_IOMAP=all nunit-console Sushi.AppleScript.Test/SushiAppleScript.Test.csproj

NUnit 3.x console:

mono $(MTOOLS)/nunit3-console.exe Sushi.AppleScript.Test/SushiAppleScript.Test.csproj

Note:

AppleScript.cs(7,7): error CS0246: The type or namespace name `MonoMac' could not be found. Are you missing an assembly reference?

If you do not have a local copy of MonoMac, xbuild will fail. It is available via “Xamarin Studio”:

mdtool build Sushi.AppleScript.sln

Example Usage:

var scptInfo = new FileInfo ("./AppleScripts/FunctionTests.txt");
string funcName = "IsRunning";
List<string> argList = new List<string> () {
    @"Finder",
};
string scriptReturnValue;
var executionSuccess = AppleScript.Run (scptInfo, funcName, argList, out scriptReturnValue);
  • Consult Test.cs for more examples

Supports:

  • MonoMac
  • Xamarin.Mac
  • i386 and x86_64 Mono Support

Runtime/Deployment debugging:

Runtime/Deployment debugging available by setting an environment variable, APPLE_SCRIPT_DEBUG:

export APPLE_SCRIPT_DEBUG=true

The results are logged with the prefix AppleScript:, output is avaiable via Console.app.

Sushi.AppleScript

The C# library that provides the P/Invoke wrapper to execute AppleScript functions

Sushi.AppleScript.Native

An OS-X Universial (i386 & x86_64) Shared Library:

  • libAppleScriptEvent.dylib

Sushi.AppleScript.Test

NUnit tests for Sushi.AppleScript library

Sushi.AppleScript.CLI

TODO: Provides an osascript style CLI utility to execute functions with AppleScript files (osascript does not contain this feature)

License:

  • The MIT License (MIT)

Xamarin Android C# bindings for Java CIFS (jCIFS) Client Library (Samba)

I posted a Samba/JCIFS binding library to my Github account…

Xamarin.Android.jCIFS

This is a C# binding library for the The Java CIFS (jCIFS) Client Library (version 1.3.18).

JCIFS is an Open Source client library that implements the CIFS/SMB networking protocol in 100% Java.

You can read/write, delete, make directories, rename, list contents of a directory, list the workgroups/ntdomains and servers on the network, list the shares of a server, open named pipes, authenticate web clients …etc.

License:

As JCIFS is Licensed Under the LGPL, so is this project’s license.

API Documentation:

Consult the jCIFS site for API documention and usage, this is a C# binding library and does not implement/change anything within the jcifs-1.3.18.jar.

Example:

Usage of Jcifs.Smb.SmbFileInputStream:

// This is NOT best-practice code, just showing a demo Jcifs api call
public async Task getFileContents ()
{
    await Task.Run (() => {
        var smbStream = new SmbFileInputStream ("smb://guest@10.10.10.5/code/test.txt");
        byte[] b = new byte[8192];
        int n;
        while ((n = smbStream.Read (b)) > 0) {
            Console.Write (Encoding.UTF8.GetString (b).ToCharArray (), 0, n);
        }
        Button button = FindViewById<Button> (Resource.Id.myButton);
        RunOnUiThread(() => {
            button.Text = Encoding.UTF8.GetString (b);
        });
    }
    ).ContinueWith ((Task arg) => {
        Console.WriteLine (arg.Status);
        if (arg.Status == TaskStatus.Faulted)
            Console.WriteLine (arg.Exception);
    }
    );
}

Note:

The entire jCIFS library is not bound by this project, consult the “Metadata.xml” file in the binding project for method renames and class exclusions.

Using redirection within xargs

I needed to convert a bunch of AppleScript .scpt files to uncompiled .txt files, so a simple find piped to xargs and I’ll be done… well…

OS-X provides a osadecompile cmd that will read a .scpt file and output the text to stdout (It does not provide a output file option). So a simple redirection and I should be done:

# This will not work, you will end up with a file 
# named {}.txt that includes the test of all the scripts
find *.scpt -print0 | xargs -0 -n 1 -I {} osadecompile '{}' > '{}.txt' 

But that will not work as the redirection applies to the xargs cmd, not the osadecompile cmd that xargs is calling. So a quick fix is to create a subshell and include the redirection in the passed cmd string (via -c)

So this will work:

find *.scpt -print0 | xargs -0 -n 1 -I {} sh -c "osadecompile '{}' > '{}.txt'"

Still simple enough, and since I only have a couple of dozen files in this case the performance impact of creaing subshells is not a problem…

Homework: How would you get around this in using a bash one-liner without a subshell?

Xamarin C# UIPickerView

A real quickie example of a UIPickerView: (iOS SDK)

Add a UIPickerView to your xib or Storyboard called slotMachineView and a label (named selectedLbl) to show the currently selected items.

using System;
using UIKit;

namespace Slots
{
    public partial class ViewController : UIViewController
    {
        public ViewController (IntPtr handle) : base (handle)
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
                slotMachineView.Model = new StackOverflowModel (selectedLbl);
        }

        public override void DidReceiveMemoryWarning ()
        {
            base.DidReceiveMemoryWarning ();
        }
    }

    public class StackOverflowModel : UIPickerViewModel
    {
        static string[] names = new string [] {
            "pscorlib.dll",
            "pscorlib_aot.dll",
            "Mono.PlayScript.dll",
            "PlayScript.Dynamic.dll",
            "PlayScript.Dynamic_aot.dll",
            "PlayScript.Optimization.dll",
            "playshell.exe",
            "psc.exe"
        };

        UILabel lbl;

        public StackOverflowModel (UILabel lbl)
        {
            this.lbl = lbl;
        }

        public override nint GetComponentCount (UIPickerView v)
        {
            return 3;
        }

        public override nint GetRowsInComponent (UIPickerView pickerView, nint component)
        {
            return names.Length;
        }

        public override string GetTitle (UIPickerView picker, nint row, nint component)
        {
            switch (component) {
            case 0:
                return names [row];
            case 1:
                return row.ToString ();
            case 2:
                return new string ((char)('A' + row), 1);
            default:
                throw new NotImplementedException ();
            }
        }

        public override void Selected (UIPickerView picker, nint row, nint component)
        {
            lbl.Text = String.Format ("{0} : {1} : {2}",
                names [picker.SelectedRowInComponent (0)],
                picker.SelectedRowInComponent (1),
                picker.SelectedRowInComponent (2));
        }

        public override nfloat GetComponentWidth (UIPickerView picker, nint component)
        {
            if (component == 0)
                return 220f;
            else
                return 30f;
        }
    }
}

From my answer on StackOverflow.

Safari - Changing the Quit Shortcut

I tend to hit the Cmd-Q instead of Cmd-W when I am closing a tab and in my older installs on OS-X I had changed the shortcut for Safari Quit and that is one thing (among others) that I did not migrate to my new OS-X 10.11 install.

So, open up System Perferences and go to KeyBoards and then the Shortcuts pane and add an App Shortcuts for Safari only for the menu item called Quit Safari, mine now is Ctrl-CMD-Q:

MonoMac - Demo / Samples updated

A number of the MonoMac demos were broken in various ways so as I was using some of them in my PlayScript / ActionScript work with Stage3d, Away3d and Starling, I update the PlayScriptRedux MonoMac repo with the corrected versions.

./AnimatingViews/bin/Debug/AnimatingViews.app
./attic/Hello/Hello.app
./ButtonMadness/bin/Debug/ButtonMadness.app
./CAQuartzComposition/bin/Debug/CAQuartzComposition.app
./CoreAnimationBook/BackgroundFilteredView/bin/Debug/BackgroundFilteredView.app
./CoreAnimationBook/CustomAnimationTiming/bin/Debug/CustomAnimationTiming.app
./CoreAnimationBook/CustomizeAnimation/bin/Debug/CustomizeAnimation.app
./CoreAnimationBook/CustomizeAnimation2/bin/Debug/CustomizeAnimation.app
./CoreAnimationBook/FilteredView/bin/Debug/FilteredView.app
./CoreAnimationBook/GroupAnimation/bin/Debug/GroupAnimation.app
./CoreAnimationBook/KeyFrameMoveAView/bin/Debug/KeyFrameMoveAView.app
./CoreAnimationBook/LayerBackedControls/bin/Debug/LayerBackedControls.app
./CoreAnimationBook/QCBackground/bin/Debug/QCBackground.app
./CoreAnimationBook/TimedAnimation/bin/Debug/TimedAnimation.app
./CoreTextArcMonoMac/bin/Debug/CoreTextArcMonoMac.app
./CoreWLANWirelessManager/bin/Debug/CoreWLANWirelessManager.app
./DatePicker/bin/Debug/DatePicker.app
./DockAppIcon/bin/Debug/DockAppIcon.app
./DocumentSample/bin/Debug/DocumentSample.app
./DrawerMadness/DrawerMadness/bin/Debug/DrawerMadness.app
./Fire/bin/Debug/Fire.app
./GLFullScreen/bin/Debug/GLFullScreen.app
./GlossyClock/bin/Debug/GlossyClock.app
./GLSLShader/bin/Debug/GLSLShader.app
./ImageKitDemoStep1/bin/Debug/ImageKitDemo.app
./macdoc/bin/Debug/macdoc.app
./MonoMacGameWindow/bin/Debug/MonoMacGameView.app
./NSAlert/bin/Debug/NSAlertSample.app
./NSTableViewBinding/bin/Debug/NSTableViewBinding.app
./OpenGL-NeHe/NeHeLesson1/bin/Debug/NeHeLesson1.app
./OpenGL-NeHe/NeHeLesson13/bin/Debug/NeHeLesson13.app
./OpenGL-NeHe/NeHeLesson17/bin/Debug/NeHeLesson17.app
./OpenGL-NeHe/NeHeLesson2/bin/Debug/NeHeLesson1.app
./OpenGL-NeHe/NeHeLesson3/bin/Debug/NeHeLesson1.app
./OpenGL-NeHe/NeHeLesson4/bin/Debug/NeHeLesson4.app
./OpenGL-NeHe/NeHeLesson5/bin/Debug/NeHeLesson5.app
./OpenGL-NeHe/NeHeLesson6/bin/Debug/NeHeLesson6.app
./OpenGL-NeHe/NeHeLesson7/bin/Debug/NeHeLesson7.app
./OpenGL-NeHe/NeHeLesson8/bin/Debug/NeHeLesson8.app
./OpenGL-NeHe/NeHeLesson9/bin/Debug/NeHeLesson9.app
./OpenGLLayer/bin/Debug/OpenGLLayer.app
./OpenGLViewSample/OpenGLViewSample/bin/Debug/MMOpenTK.app
./PopupBindings/bin/Debug/PopupBindings.app
./PredicateEditorSample/bin/Debug/PredicateEditorSample.app
./QTRecorder/bin/Debug/QTRecorder.app
./RoundedTransparentWindow/bin/Debug/RoundedTransparentWindow.app

MonoMac - Where is the CAEmitterCell Content propery?

I was trying to integrate ActionScript and Away3d with the CAEmitterCell particles using MonoMac for users that do not have access (a license) to Xamarin.Mac, but…

The MonoMac project is missing the maccore CoreAnimation/CAEmitterCell.cs in the Make.shared and thus the MonoMac.dll that is distributed via Xamarin Studio is broken in this regard as it is missing the ability to assign an Image to the emitter.

Example:

            // Create the fire emitter cell
            CAEmitterCell fire = CAEmitterCell.EmitterCell ();
            fire.EmissionLongitude = (float)Math.PI;
            fire.BirthRate = 0;
            fire.Velocity = 80;
            fire.VelocityRange = 30;
            fire.EmissionRange = 1.1f;
            fire.AccelerationY = 200;
            fire.ScaleSpeed = 0.3f;

            RectangleF rect = RectangleF.Empty;
            CGColor color = new CGColor (0.8f,0.4f,0.2f,0.10f);
            fire.Color = color;
            fire.Contents = NSImage.ImageNamed ("fire.png").AsCGImage (ref rect, null, null);

I have updated PlayScript’s MonoMac (forked from Mono/MonoMac) to fix this.

git diff src/Make.shared

diff --git a/src/Make.shared b/src/Make.shared
index 986ff28..a84aeae 100644
--- a/src/Make.shared
+++ b/src/Make.shared
@@ -44,6 +44,7 @@ SHARED_SOURCE = \
        ./CoreAnimation/CALayer.cs                      \
        ./CoreAnimation/CATextLayer.cs                  \
        ./CoreAnimation/CAMediaTimingFunction.cs        \
+       ./CoreAnimation/CAEmitterCell.cs                \
        ./CoreFoundation/CFArray.cs                     \
        ./CoreFoundation/CFBoolean.cs                   \
        ./CoreFoundation/CFDictionary.cs                \

CursesSharp (C# NCurses) Updated

I made some updates to the CursesSharp project, so check out the update README.md for details:

CursesSharp

INTRODUCTION

CursesSharp is a C# wrapper for curses library. The latest version of this ‘fork’‘ can be found at Github. The original version can be found at the SourceForge.net project page.

RainDemo

DOCUMENTATION

CursesSharp consists of a .NET assembly (CursesSharp.dll) and a native wrapper shared library (DLL) which is linked with PDCurses (in Windows) or ncurses (in Unix-like systems). This wrapper library is called CursesWrapper.dll in Windows or libCursesWrapper.so in Unix or libCursesWrapper.dylib in OS-X. CursesSharp provides a bit cleaner API to curses than the original one, although function names remain unchanged for the most part.

CursesSharp namespace contains several important classes:

  • Defs - contains constants from curses: attribute, color and key definitions as well as some macros (COLOR_PAIR, PAIR_NUMBER)
  • Curses - the main interface to curses; contains methods global to the library, a StdScr property that returns the stdscr window, and as a convenience, some window-specific functions that operate on stdscr
  • Window - represents a curses window that can be written to, or read from; contains wrappers for most of curses functions with names starting with w or mvw
  • CursesException - an exception class, thrown when a curses function reports an error

Documentation is (always) under construction. Help would be much appreciated.

Installing CursesSharp on OS-X

These are the instructions for building CursesSharp on OS-X.

The build process has been tested on:

  • OS-X 10.10.5
  • Apple LLVM version 7.0.0 (clang-700.1.76)
  • Mono JIT compiler version 4.2.1 64-bit build.

0. Prerequisites

The native library is now built as a ‘fat’ library so either a Mono 32-bit or 64-bit build can be used.

$> file libCursesWrapper.so

libCursesWrapper.so: Mach-O universal binary with 2 architectures
libCursesWrapper.so (for architecture i386):    Mach-O dynamically linked shared library i386
libCursesWrapper.so (for architecture x86_64):  Mach-O 64-bit dynamically linked shared library x86_64

1. Getting CursesSharp

You can clone it from the following repository:

https://github.com/sushihangover/CursesSharp.git

2. Make the Native Library

mdtool build CursesSharp.Native.sln --target:Build --configuration:Release
mdtool build CursesSharp.Native.sln --target:Build --configuration:Debug

3. Make the C# Libraries and Demos

xbuild CursesSharp.sln /target:Clean
xbuild CursesSharp.sln /target:Build

Note: To run the demos from the CLI, make sure that set the DYLD_FALLBACK_LIBRARY_PATH. While still in the repo’s root directory:

export DYLD_FALLBACK_LIBRARY_PATH=$(PWD)/CursesSharp.Native/bin/Debug:/usr/lib:$DYLD_FALLBACK_LIBRARY_PATH

There is also a CI script that can be called via source to setup DYLD_FALLBACK_LIBRARY_PATH and LD_LIBRARY_PATH

source CI/libpath-source-me.sh

To learn more about dyld check out the man page:

man dyld

Demos:

There are various demos available to review:

  • Demo.CursesSharp.Firework
  • Demo.CursesSharp.Gui.HelloWorld
  • Demo.CursesSharp.HelloWorld
  • Demo.CursesSharp.Rain
  • Demo.CursesSharp.Unicode
  • Demo.Gui.MessageBox
  • Demo.Gui.MidnightCommander
  • Demo.Gui.Timeout
  • Demo.Native.ResizeTerm

Rain Demo:

pushd CursesSharp.Demo/Demo.CursesSharp.Rain/bin/x64/Debug/
mono RainDemo.exe
popd

RainDemo

FireWorks Demo:

pushd CursesSharp.Demo/Demo.CursesSharp.Rain/bin/x64/Debug/
mono FireworkDemo.exe
popd

MidnightCommander Demo:

pushd CursesSharp.Demo/Demo.Gui.MidnightCommander/bin/x64/Debug/
mono Demo.Gui.MidnightCommander.exe
popd

Installing CursesSharp on Linux

0. Prerequisites

Note: It is assumed you are running 64-bit Linux (ARCH x86_64)

Install some dependencies:

sudo apt-get install lib32ncursesw5-dev
sudo apt-get install lib32ncurses5-dev
sudo apt-get install ncurses-doc

1. Getting CursesSharp

You will have to obtain CursesSharp sources. You clone it from the following repository:

https://github.com/sushihangover/CursesSharp.git

2. Make the Native Library

mdtool build CursesSharp.Native.Linux.sln --target:Build --configuration:Release
mdtool build CursesSharp.Native.Linux.sln --target:Build --configuration:Debug

3. Make the C# Libraries and Demos

xbuild CursesSharp.sln /target:Clean /property:configuration=Debug
xbuild CursesSharp.sln /target:Build /property:configuration=Debug

Demos:

Note: To run the demos from the CLI, make sure that set the LD_LIBRARY_PATH. While still in the repo’s root directory:

export LD_LIBRARY_PATH=$(PWD)/CursesSharp.Native/bin/Debug:/usr/lib:$LD_LIBRARY_PATH

There is also a CI script that can be called via source to setup DYLD_FALLBACK_LIBRARY_PATH and LD_LIBRARY_PATH

source CI/libpath-source-me.sh

To learn more about ld check out the man page:

man ld

MessageBox Demo:

cd CursesSharp.Demo/Demo.Gui.MidnightCommander/bin/x64/Debug/
mono Demo.Gui.Messagebox.exe
cd -
(Ubuntu / Konsole)

MidnightCommander Demo:

cd CursesSharp.Demo/Demo.Gui.MidnightCommander/bin/x64/Debug/
mono Demo.Gui.MidnightCommander.exe
cd -

(Ubuntu / Konsole)

Installing CursesSharp on Windows

Refer the original Windows project, source code and instructions are here

CI

OS-X:

source CI/libpath-source-me.sh
CI/build.osx.sh

Linux:

{TODO}

TODO & Contributors:

  • Nuget support
  • MS Window support (via PDCurses)
  • Documentation
  • Bug reporting/fixes

Looking for contributors in these areas and/or any other areas that you would help out on.

Fork and Contribute ;-)

Xamarin Studio mdtool - Where is it?

I’m not sure if it is a bug or not, but older versions of Xamarin Studio (and MonoDevelop) on OS-X (prior to El Capitan) installed a mdtool shell script in /usr/local/bin but that no longer happens(?).

mdtool original/missing shell script:

#!/bin/bash
MONO_EXEC="exec mono-sgen"
EXE_PATH="/Applications/Xamarin Studio.app/Contents/Resources/lib/monodevelop/bin/mdtool.exe"
$MONO_EXEC $MONO_OPTIONS "$EXE_PATH" "$@"

So create the script with the content above and place it into a directory in your path. /usr/local/bin is fine, but I personally install my shell scripts into a $HOME/.scripts directory that is included in my path so I can backup, via a git repo, my personal scripts and distinguish what I have created verus what gets installed in the /usr/local/bin by applications such a brew

Note: Make sure that you chmod a+x mdtool in order to make it executable…

As always, have fun… ;-)

$mdtool

Xamarin Studio Tool Runner

Usage: mdtool [options] <tool> ... : Runs a tool.
       mdtool setup ... : Runs the setup utility.
       mdtool -q : Lists available tools.

Options:
  --verbose (-v)   Increases log verbosity. Can be used multiple times.
  --no-reg-update  Skip updating addin registry. Faster but results in
                   random errors if registry is not up to date.

Available tools:
- build: Project build tool
- dbgen: Parser database generation tool
- project-export: Project conversion tool
- gsetup: Graphical add-in setup utility
- archive: Project archiving tool
- account: Xamarin account tool
- mac-bundle: Mac application bundle and installer generator.

NUnit Console 2.4.8 vs 3.0 using .csproj files

When using NUnit console 2.4.x and 3.x with .csproj files, it expects a valid and fairly complete MSBuild/xbuild project to determine the assembly name, dir location, and namespace that it will test in the Library-based project (Exe-based projects are possible if you have defined the proper entry point). In this example I used NUnit 2.4.x and 3.x console as there are execution differences but the same .csproj is being used so if you are using MonoDevelop/Xamarin Studio the IDE’s built-in NUnit 2.4.x test pad will also work.

NUnit 3.0 console (Install via nuget):

mono $(MTOOLS)/nunit3-console.exe  nunit-lib/nunit-lib.csproj --config=Debug

NUnit Console Runner 3.0.5797 
Copyright (C) 2015 Charlie Poole

Runtime Environment
   OS Version: MacOSX 15.0.0.0 
  CLR Version: 4.0.30319.17020

Test Files
    nunit-lib/nunit-lib.csproj

Errors and Failures

1) Failed : nunitlib.Test.TestCase
  Expected string length 8 but was 5. Strings differ at index 0.
  Expected: "Overflow"
  But was:  "Stack"
  -----------^
at nunitlib.Test.TestCase () in <filename unknown>:line 0

Test Run Summary
    Overall result: Failed
   Tests run: 1, Passed: 0, Errors: 0, Failures: 1, Inconclusive: 0
     Not run: 0, Invalid: 0, Ignored: 0, Explicit: 0, Skipped: 0
  Start time: 2015-11-20 12:36:28Z
    End time: 2015-11-20 12:36:28Z
    Duration: 0.132 seconds

NUnit 2.4.8 (installed via Mono):

NOTE: NUnit console 2.4.x is broken due a hard-coded Windows-style Directory Separator when parsing .csproj files and creating the expected CIL/assembly location, use MONO_IOMAP to work around it. This is not a issue in 3.0.

NUnit Console 2.4.x w/o MONO_IOMAP:

nunit-console nunit-lib/nunit-lib.csproj -config=Debug
~~~~
Unhandled Exception:
System.IO.DirectoryNotFoundException: Directory "/Users/sushi/code/XamTests/nunit-lib/nunit-lib/bin\Debug" not found.
~~~~

NUnit Console 2.4.x with MONO_IOMAP:

MONO_IOMAP=all nunit-console nunit-lib/nunit-lib.csproj -config=Debug

NUnit version 2.4.8
Copyright (C) 2002-2007 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment - 
   OS Version: Unix 15.0.0.0
  CLR Version: 4.0.30319.17020 ( 4.2.1 (explicit/8862921 Thu Oct 29 17:09:16 EDT 2015) )

.F
Tests run: 1, Failures: 1, Not run: 0, Time: 0.115 seconds

Test Case Failures:
1) nunitlib.Test.TestCase :   Expected string length 8 but was 5. Strings differ at index 0.
  Expected: "Overflow"
  But was:  "Stack"
  -----------^

.csproj example used in for example:

<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
    <ProjectGuid>{944946CD-39B2-4A16-A8A8-9F70F0450506}</ProjectGuid>
    <OutputType>Library</OutputType>
    <RootNamespace>nunitlib</RootNamespace>
    <AssemblyName>nunit-lib</AssemblyName>
    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
    <DebugSymbols>true</DebugSymbols>
    <DebugType>full</DebugType>
    <Optimize>false</Optimize>
    <OutputPath>bin\Debug</OutputPath>
    <DefineConstants>DEBUG;</DefineConstants>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
    <DebugType>full</DebugType>
    <Optimize>true</Optimize>
    <OutputPath>bin\Release</OutputPath>
    <ErrorReport>prompt</ErrorReport>
    <WarningLevel>4</WarningLevel>
    <ConsolePause>false</ConsolePause>
  </PropertyGroup>
  <ItemGroup>
    <Reference Include="System" />
    <Reference Include="nunit.framework">
      <HintPath>..\packages\NUnit.2.6.4\lib\nunit.framework.dll</HintPath>
    </Reference>
  </ItemGroup>
  <ItemGroup>
    <Compile Include="Test.cs" />
  </ItemGroup>
  <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
  <ItemGroup>
    <None Include="packages.config" />
  </ItemGroup>
</Project>

Ref: This was my answer on StackOverflow