I've been spending a lot of time working on the game-play for the dungeon-type game for the Zune. Along the way, I've learned a lot about XNA. It's not as bad as I thought. It's just a bunch of new classes to understand. The programming concepts are still the same. I was initially worried that XNA would be so limited as to require a more procedural approach to coding, but I'm glad to see that's not true. I have classes, inheritance, and events. That's all I need to start.
I'd been doing pretty well testing the game out in a winform container, but I really wanted to see how it would run on the Zune. Unfortunately, every time I started the game on the Zune, it would reboot. I knew that the Zune XNA didn't support VB, so I researched getting rid of the reference to the VB runtime. I found the magic switch and recompiled. The VB runtime was gone. I thought that was it, but I still had more to go. Every few days, I'd try again and see if it would dawn on me. Tonight it did. I still had a reference to the 2.0 mscorlib in addition to the 3.5 version. After setting another magic switch, I was able to run the game on the Zune. Happiness!
So, here's what I did. I created a batch file, build.bat. I built the project in VS2005 and copied the vbc.exe command line out of the output window. I pasted this into the batch file. Then I made the following changes.
Original:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:System,System.Collections,System.Collections.Generic /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optionstrict+ /rootnamespace:DungeonXNAGame /doc:obj\Release\DungeonXNAGame.xml /define:"CONFIG=\"Release\",TRACE=-1,_MyType=\"WindowsFormsWithCustomSubMain\",PLATFORM=\"AnyCPU\"" /reference:D:\Projects\cbDungeon\DungeonObjects\bin\Release\DungeonObjects.dll,"C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Windows\x86\Microsoft.Xna.Framework.dll","C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Windows\x86\Microsoft.Xna.Framework.Game.dll",C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll,
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll,C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll,
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.XML.dll /debug- /optimize+ /out:obj\Release\DungeonXNAGame.exe
/target:winexe Components\CompassComponent.vb Components\MapComponent.vb DungeonXNAGame.vb GameStart.vb "My Project\AssemblyInfo.vb"
Changed:
C:\WINDOWS\Microsoft.NET\Framework\v3.5\Vbc.exe /sdkpath:"C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Zune" /noconfig /verbose /nostdlib /novbruntimeref /imports:System,System.Collections,System.Collections.Generic /nowarn:42016,41999,42017,42018,42019,42032,42036,42020,42021,42022 /optionstrict+ /rootnamespace:DungeonXNAGame /define:"_MyType=\"Empty\"" /reference:D:\Projects\cbDungeon\DungeonObjects\bin\Release\DungeonObjects.dll,"C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Zune\Microsoft.Xna.Framework.dll","C:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Zune\Microsoft.Xna.Framework.Game.dll","c:\Program Files\Microsoft XNA\XNA Game Studio\v3.0\References\Zune\System.Xml.dll" /debug- /optimize+ /out:bin\Release\DungeonXNAGame.dll /target:library Components\CompassComponent.vb Components\MapComponent.vb DungeonXNAGame.vb
Can you spot the differences? Here they are:
- Path to vbc.exe changed from version v2.0.50727 to v3.0
- Added /sdkpath switch. This points to the XNA framework root for the Zune files. This gets rid of the mscorlib 2.0 reference
- Added /verbose (so I can see what's going on)
- Added /nostdlib (gets rid of unneeded references)
- Added /novbruntimeref (gets rid of Microsoft.VisualBasic reference)
- Modified references to point to Zune versions of DLLs
- Changed /define switch to use \"Empty\" This makes sure that the "My" namespace is not created. Creating the My namespace results in a reference to the VB runtime.
- Changed output type and destination with /out and /target
- Removed reference to assemblyinfo.vb. That might not be required, but just to be minimal...
So the main switches you need to work with are: /sdkpath, /novbruntimeref and /define and also make sure you use the right vbc version (3.0). Just use that build.bat from the command line to create your libraries.
Now that I've seen the game run on the Zune, I'm going to drop my reservations about coding the game in VB. All the C# snobs who think they're the only ones that matter can go suck a semicolon.