PowerShell, Learn it or Perish ;-)

master nix

PlayScript | Away3d World Global Example

I finally got all the bits together to get the OS-X OpenGL version of the PlayScript flash stage running the Away3d 3D engine.

500 ActionScript files with over 20000 lines of actual code from away3d-core-fp11 and away3d-examples-fp11 compiled to CIL using the PlayScript mcs compiler. :-)

Using PlayScript, the Actionscript compiler for Mono, to compile and run the Away3d core and Intermediate_Globe example within Xamarin Studio 5.9.x PlayScript @ PlayScript Source Code @ Blogging @ Royalty Free Background Music by Origen from:

Away3d example source code that is running in the demo

>cloc away3d-core-fp11
     464 text files.
     464 unique files.
      16 files ignored. v 1.62  T=3.45 s (130.1 files/s, 23410.8 lines/s)
Language                     files          blank        comment           code
ActionScript                   443          12601          12443          54059
MSBuild script                   3              0              0           1551
C#                               3             39             11            111
SUM:                           449          12640          12454          55721
>cloc away3d-examples-fp11
     110 text files.
     109 unique files.
      60 files ignored. v 1.62  T=5.05 s (10.5 files/s, 3247.7 lines/s)
Language                     files          blank        comment           code
ActionScript                    36           1936           2592           8073
Javascript                       2            121            148           1186
MSBuild script                   3              0              0            808
C#                               7            414             99            740
XML                              2             19             10            105
HTML                             2              7             29            102
CSS                              1              1              1              4
SUM:                            53           2498           2879          11018

Note: ScreenFlow is running on the background so the world rotation is a little choppy at times, without the screen/video capture running, the example runs at 60 fps @ 4% CPU on this old MacBookPro with a Intel Core 2 Duo 2.53 GHz processor.

FYI: ScreenFlow is a must have if you are screen capturing video on OS-X. It really is the bomb at what it does.

Xamarin Studio / MonoDevelop - 'Unexpected binary element: 0' build failure

Getting an ‘Unexpected binary element: 0’ when you are trying to build a project in Xamarin Studio / MonoDevelop? I found this when using a parallal mono install on OS-X and it seems others have also.

If you are also getting it build failure, please add your findings to:

Bug 29958 - Mono 4.0 - Causing ‘Unexpected binary element: 0’ build failure when compiling against previous mono version

It appears not to be OS dependent either:

Building empty ASP.NET project in MonoDevelop (Xamarin Studio) generates “Unexpected binary element: 0” error

Git - Squash last X commits into one

Use git rebase -i and replace “pick” on the second and subsequent commits with “squash” or “fixup”, as described in the Git manual.

is the commit after the last one that you wish squash together, i.e. parent of the oldest commit you want to squash.


You want to squash the last three commits into one, so lets look at the log to make sure that is want you want and to grab the commit SHA:

git log -n 4 –pretty=oneline

f57f7f9c28646d5049aa6b90f33de23e1e53ad2e More test cleanups
07074c8058ed69224670987860c9db47858dab6e PlayScript compiler tests using a variant of compiler-tester
3b80dc06b990553042b4b0cde486e36522f4171b Remove .as/.play from mcs/tests These have been already moved to mcs/play_tests/[as|play] and intregrated into the mono compiler-tester (make [astest|playtest|playscript]
db6506ca17e49f0829ca9859a7994ddf840dbff4 * Tamarin-Redux Test Cleanup * Remove old Tamarin tests, the redux versions are the last released version

I want to squash the first three commits, so grab the forth SHA and:

git rebase -i db6506ca17e49f0829ca9859a7994ddf840dbff4

pick 3b80dc0 Remove .as/.play from mcs/tests These have been already moved to mcs/play_tests/[as|play] and intregrated into the mono compiler-tester (make [astest|playtest|playscript]
pick 07074c8 PlayScript compiler tests using a variant of compiler-tester
pick f57f7f9 More test cleanups

# Rebase db6506c..f57f7f9 onto db6506c (3 command(s))

Following the directions in the commentted text. In this example: change the second and third items to squash:

pick 3b80dc0 Remove .as/.play from mcs/tests These have been already moved to mcs/play_tests/[as|play] and intregrated into the mono compiler-tester (make [astest|playtest|playscript]
squash 07074c8 PlayScript compiler tests using a variant of compiler-tester
squash f57f7f9 More test cleanups

# Rebase db6506c..f57f7f9 onto db6506c (3 command(s))

Save those changes and exit the editor and the rebase will execute

[detached HEAD ~~~
Successfully rebased and updated refs/heads/play-tests.

Confirm via:

git log -n 2

FYI: This is something you should do to your feature branch before pushing to your fork to make that PlayScript pull request. ;-)

PlayScript : Tests are now structured like Mono's

I moved all the .play and .as tests under the play_test directory. They are in two separtate dirs now, play for the extended PlayScript language/format and as for the standard ActionScript tests.

In doing this and making them conform to how Mono’s compiler tests are written and run, I ended up copying the tools/compiler-tester to tools/playc-tester. The number of changes I was making to the program seems out of place to keep in within Mono’s version and long term this will keep up with trying to keep any changes to the actual Mono code base at a minimun to allow faster and cleaner merging of their master branch. This tool will have very little commit activity compared to the mcs.exe/playc.exe compilers.


mono playc-tester.exe
PlayScript compiler tester, (C) 2009 Novell, Inc. (C) SushiHangover/RobertN
playc-tester -mode:[pos|neg] -compiler:FILE -files:file-list [options]

   -compiler:FILE   The file which will be used to compiler tests
   -compiler-options:OPTIONS  Add global compiler options
   -il:IL-FILE      XML file with expected IL details for each test
   -issues:FILE     The list of expected failures
   -log:FILE        Writes any output also to the file
   -help            Lists all options
   -mode:[pos|neg]  Specifies compiler test mode
   -safe-execution  Runs compiled executables in separate app-domain
   -update-il       Updates IL-FILE to match compiler output
   -update-ref      Updates the debug xml to match debug compiler mdb output
   -verbose         Prints more details during testing

Example test run of the current as tests:

make astest
./as/   NOT TESTED
./as/ KNOWN ISSUE (Execution error)
./as/      KNOWN ISSUE (Compilation error)
./as/   KNOWN ISSUE (Compilation error)

40 test cases passed (93.02%)
1 test(s) ignored
3 known issue(s)

With these changes and the addition of the playshell REPL in the last set of changes will allow the Tamarin Redux tests to start coming online. Then CI deployment will be the step after that.

As always post any isses that you find. ;-)

PlayScript - Now has a REPL (playshell)

PlayScript now has a REPL for ActionScript scripting. This is very alpha right now and needs a lot of love. It will be used for running the Tamarin Redux acceptance tests so it will be evolving as those regression tests come online.

It is available in the master branch : 17aac5473528370b96e3349751bd2a8a017e6779

Check it out and post any issues that you find.

* Added playshell : This is a PlayScript REPL (aka: like csharp REPL)
  - For use with Tamarin Redux test; they use Asset scripts with a test package
  - Very alpha at this point
  - Need to add PlayScript style 'import'
* Added PsOnlyMode to compiler setting
  - Whether to enable PlayScript compiler only mode. Defaults to false.
* mcs.master.mdw : XS/MD Workspace that will hold Solutions for all mcs
  - Added tools/csharp and tools/playshell
* CSProj files updated via Make2CSProjUpdater to allow use in XS/MD:
  - Mono.PlayScript.csproj (and .sln)
  - Mono.CSharp.csproj (and .sln)
  - tools/charp.csproj (and .sln)
  - tools/playshell.csproj (and .sln)

PlayScript Redux - Make2CSProjUpdater

I just posted a new tool project on Github that I am using with Mono and PlayScript to make things easier with Xamarin Studio / MonoDevelop.


Update the .csproj ItemGroup/Compile elements from a sourcefile list.

This project takes a source list of file, usually from an external Makefile source (i.e. Mono.CSharp.dll.sources) and a C# (.csproj) project file and will update/sync the source list into the project file.

As an author of the PlayScript Redux project, there are a large number of Mono .csproj files that are not keep up to date with the Makefile source lists. The Makefile source lists are a known good source as they are used to build Mono and the project files are not used in that capicity. But in development and debugging of the Mono Compiler (mcs.exe) and PlayScript Compiler (playc.exe), the use of Xamarian Studio / MonoDevelop IDE makes life so much easier and thus the need for up to date project (.csproj) files. :-)

Note: This project is generic, just a text file containing a list of filenames and a .csproj file.

Note: Found another use; dumping a list of files via find/ls/etc. to a file and updating a blank project file with that source. This provided a quick jumpstart for a few projects that did not include project files or were so outdated that the project files had to be recreated.


make2csprojupdater.exe -h
Make2CSProjectUpdate / ©SushiHangover 2015
Update the .csproj ItemGroup/Compile elements from a sourcefile list.

  -p, --proj=VALUE           The project filename (.csproj) to update.
  -s, --sources=VALUE        The filename of the Makefile source list.
  -i, --interactive          Confirmation prompt to update/save the project
  -v, --verbose              Increase message verbosity.
  -h, --help                 Show this message and exit

Sample Usage:

  mono make2csprojupdater.exe -p Sample/Mono.CSharp.csproj -s Sample/Mono.CSharp.dll.sources -v -i
# Make source files : 68
# Project source files  : 58

# Project needs the following changes    : Sample/Mono.CSharp.csproj
# Delete:   ..\..\mcs\doc-bootstrap.cs
# Delete:   cs-parser.cs
# Delete:   ..\corlib\Mono.Security.Cryptography\CryptoConvert.cs
# Delete:   ..\Mono.CompilerServices.SymbolWriter\MonoSymbolFile.cs
# Delete:   ..\Mono.CompilerServices.SymbolWriter\MonoSymbolTable.cs
# Delete:   ..\Mono.CompilerServices.SymbolWriter\MonoSymbolWriter.cs
# Delete:   ..\Mono.CompilerServices.SymbolWriter\SourceMethodBuilder.cs
# Add:  ../../mcs/ps-lang.cs
# Add:  ../../mcs/ps-tokenizer.cs
# Add:  ../../mcs/ps-codegen.cs
# Add:  ../../mcs/cxx-emit.cs
# Add:  ../../mcs/cxx-target.cs
# Add:  ../../mcs/inliner.cs
# Add:  ../../mcs/intrinsics.cs
# Add:  ../../mcs/js-emit.cs
# Add:  ../../mcs/js-target.cs
# Add:  ../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
# Add:  ../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
# Add:  ../../class/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs
# Add:  ../../class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
# Add:  ../../build/common/Consts.cs
# Add:  ../../mcs/cs-parser.cs
# Add:  ../../mcs/ps-parser.cs
# Add:  Assembly/AssemblyInfo.cs

Make changes? [y/n]:y
# Saving backup:    Sample/Mono.CSharp.csproj.bak
# Deleting: ..\..\mcs\doc-bootstrap.cs
# Deleting: cs-parser.cs
# Deleting: ..\corlib\Mono.Security.Cryptography\CryptoConvert.cs
# Deleting: ..\Mono.CompilerServices.SymbolWriter\MonoSymbolFile.cs
# Deleting: ..\Mono.CompilerServices.SymbolWriter\MonoSymbolTable.cs
# Deleting: ..\Mono.CompilerServices.SymbolWriter\MonoSymbolWriter.cs
# Deleting: ..\Mono.CompilerServices.SymbolWriter\SourceMethodBuilder.cs
# Adding:   ../../mcs/ps-lang.cs
# Adding:   ../../mcs/ps-tokenizer.cs
# Adding:   ../../mcs/ps-codegen.cs
# Adding:   ../../mcs/cxx-emit.cs
# Adding:   ../../mcs/cxx-target.cs
# Adding:   ../../mcs/inliner.cs
# Adding:   ../../mcs/intrinsics.cs
# Adding:   ../../mcs/js-emit.cs
# Adding:   ../../mcs/js-target.cs
# Adding:   ../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
# Adding:   ../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
# Adding:   ../../class/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs
# Adding:   ../../class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
# Adding:   ../../build/common/Consts.cs
# Adding:   ../../mcs/cs-parser.cs
# Adding:   ../../mcs/ps-parser.cs
# Adding:   Assembly/AssemblyInfo.cs
# Saving project:   Sample/Mono.CSharp.csproj

Git - Turn multiple commits into a single commit

Getting ready for an upstream pull request? You really need to turn it into a single commit for a clean request that will result in a fast-forward merge.

Switch to the upstream/master branch and make sure you are up to date.

git checkout master
git fetch upstream/master   
git merge master

Create a new feature/topic branch:

git checkout -b MyPullRequest
git merge MyMultiCommitBranch

Reset the branch to origin’s state.

git reset origin/MyPullRequest
git status

Note: Git now considers all changes as unstaged changes.

We can add these changes as one commit.

git add --all
git commit

You can push those changes to your remote repo and then issue that pull request to the upstream that you forked from.

Git - Create a new branch with non-commited changes

Have you started making changes and than realize that you should have created a new branch first. Well, there is a slick way to create a new branch and have those changes ‘moved’ to from master to your topic (the new branch).

git branch newbranch
git reset --hard HEAD
git checkout newbranch

This works even if you have made commits to your local branch, just subsititute HEAD with the number of commits back you would like to go, i.e. HEAD~2, or use the SHA.

OS-X + Mono + Rosyln + CodeFormatter

CodeFormatter is a tool that uses Roslyn to automatically rewrite the source to follow Microsoft’s coding styles, which are documented here.

CodeFormatter has been released as open-source for 6 months now, but I have not had a chance to look at it.

With Roslyn compiling on OS-X and I had a couple of projects that really needed to be cleaned up, I thought I would give it a try.

15 minutes in total to clone the repo and get things built properly, would have been quicker but the VS solution file is not very Xamanin Studio/MonoDevelop friendly as it includes ToolVersion 14 items (That would be included in VS 2015 beta).

But those projects are not needed to get the main program working…

mono ./CodeFormatter.exe

Must specify at least one project / solution / rsp to format
CodeFormatter [/file:<filename>] [/lang:<language>] [/c:<config>[,<config>...]>]
    [/copyright:<file> | /nocopyright] [/tables] [/nounicode]
    [/rule(+|-):rule1,rule2,...]  [/verbose]
    <project, solution or response file>

    /file        - Only apply changes to files with specified name
    /lang        - Specifies the language to use when a responsefile is
                   specified. i.e. 'C#', 'Visual Basic', ... (default: 'C#')
    /c           - Additional preprocessor configurations the formatter
                   should run under.
    /copyright   - Specifies file containing copyright header.
                   Use ConvertTests to convert MSTest tests to xUnit.
    /nocopyright - Do not update the copyright message.
    /tables      - Let tables opt out of formatting by defining
    /nounicode   - Do not convert unicode strings to escape sequences
    /rule(+|-)   - Enable (default) or disable the specified rule
    /rules       - List the available rules
    /verbose     - Verbose output

mono ./CodeFormatter.exe /rules

Name                 Description
BraceNewLine         :Ensure all braces occur on a new line
Copyright            :Insert the copyright header into every file
NewLineAbove         :Ensure there is a new line above the first namespace and using in the file
CustomCopyright      :Remove any custom copyright header from the file
UsingLocation        :Place using directives outside namespace declarations
UnicodeLiterals      :Use unicode escape sequence instead of unicode literals
ExplicitVisibility   :Ensure all members have an explicit visibility modifier
IllegalHeaders       :Remove illegal headers from files
FormatDocument       :Run the language specific formatter on every document
ExplicitThis         :Remove explicit this/Me prefixes on expressions except where necessary
ReadonlyFields       :Mark fields which can be readonly as readonly
FieldNames           :Prefix private fields with _ and statics with s_

I’ll be checking next to see if it really works on some source code. ;-)

Mono - NUnit Hello World

From my Answer for “Run NUnit test on Ubuntu from command line” on Stackoverflow:

Lets start from the beginning:

Get the latest and greatest NUnit AND it’s Runner tools

curl -o nuget.exe
mono nuget.exe install NUnit
mono nuget.exe install NUnit.Runners

Make sure the mono is finding those assemblies first (vs the GAC)

export MONO_PATH=$(PWD)/NUnit.Runners.2.6.4/tools;$(PWD)/NUnit.2.6.4/lib

Create your test example (save it to vi OnlyTest.cs):

using System;
using System.Text;
using System.Collections.Generic;
using NUnit.Framework;

public class OnlyTest
    public void MyTest() 
        int a = 10;
        Assert.AreEqual(10, a);

Compile it:

  mcs OnlyTest.cs -target:library -r:NUnit.2.6.4/lib/nunit.framework.dll -out:OnlyTest.dll

Run it:

mono ./NUnit.Runners.2.6.4/tools/nunit-console.exe OnlyTest.dll -noresult


Using default runtime: v4.0.30319
NUnit-Console version
Copyright (C) 2002-2012 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
  CLR Version: 4.0.30319.17020 ( Mono 4.0 ( 4.3.0 (master/b044a27 Thu Jun 18 15:17:08 PDT 2015) ) )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: mono-4.0
Tests run: 1, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.0280499 seconds
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0