# Actually Implementing "C# as a scripting Language" in XNA

Following an example from this thread, I've made an application that dynamically loads in C# "scripts" (actually, plugins) into my game -- but I've hit a snag: how do I reference the assemblies for XNA when compiling? Can I even be sure the XNA assemblies will be around on the end-user's machine?

This line from the example:

 options.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location); 

Adds the referenced assemblies for my game only, not the XNA assemblies (for instance, for Vector3, Matrix, etc.). The only way to add the assemblies seems to be inlining an absolute URI to the necessary .dll files.

EDIT: Looking at this thread I have discovered how to load all of the required assemblies:

foreach (AssemblyName assemblyName in executingAssembly.GetReferencedAssemblies())


But apparently the XNA assemblies aren't included in this list for me :(

• I'm confused. If your game is built on XNA and has the assemblies, why do you need them anywhere else? Your game will load the plugin and already have the correct assemblies ref? Apr 28, 2015 at 15:38
• I guess that's what I'm asking. When I distribute my game, where are the assemblies going to be located? Apr 28, 2015 at 16:03
• For an XNA game to run the user must have (which is usually included with the game distribution) whatever XNA redist you built your game off of. So you can assume, after install, that the user will have the files. I believe they go to C:\Program Files (x86)\Microsoft XNA\XNA Game Studio\v4.0\References\Windows\x86 for 4.0...look around in there! Apr 28, 2015 at 16:20
• I see, the assemblies are included in the redistributable, and the user doesn't have to download XNA 4.0? Apr 28, 2015 at 16:21
• That's what the redist is. Compiled versions of XNA 4.0 that contain all the code that is referenced by your game. So instead of installing the SDK of xna or anything of that nature, you just provide them with the redistributable. Apr 28, 2015 at 16:33

You could sum it up like such:

Pre-game install: You can't assume they are there.

Post-game install: You can assume (hope) that the XNA 4.0 Redistributable installed correctly and the assemblies reside in their respected locations.

If the scripting that the user will be doing is tested and run solely in game, then I would think that this is a safe route to go to assume the assemblies are in place or the game wouldn't even be working.

If you create some kind of "scripting editor" it's probably not going to require the same assemblies as a game. Like you stated in your question, Vector3, etc are MOST LIKELY not required to build a "text/script editor", and therefore it wouldn't be safe to assume they are.

As always with XNA Games, make sure you include the appropriate Redistributable and you will be fine.

• thank you, for the record my "scripts" are just going to be in data files loaded at runtime, and exist mainly to make it really easy for me to create many many kinds of entities. The only "users" who will access these files are potentially modders. Apr 28, 2015 at 17:57
• That's a cool concept. I wish more AAA titles would go back to being friends with modders. Apr 29, 2015 at 12:05