RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

The Perfect Solution [Visual Studio 2008]

Vorspire

Knight
The Perfect Solution [Visual Studio 2008]

The Perfect Solution
A Step-By-Step Guide to Visual Studio 2008 (All Version) Project Setup

__________________________________________________

Are you developing your scripts with Wordpad, or worse, Notepad?
STOP!
__________________________________________________

I often see new developers with some simple problems, whether it be silly syntax errors or simple typos to the ever popular 'Does not exist in the current context' error or 500 errors generated by a single missing code-block bracer.

Well I've decided to try and cut our silliness down by at least 50% by presenting you with this extremely easy-to-follow step-by-step tutorial on setting up your RunUO scripts as a project in Visual Studio 2008 C# Express.

__________________________________________________

#1

First off, you'll need Visual Studio (There are a few versions but 2008 Express is 100% free); Visual C# 2008 Express Edition
It may take a while to install, but it's sure-as-hell worth it...

__________________________________________________

#2

It's time to set-up your development environment, follow this simple list of sub-steps;
  • Start VS
  • Click View -> Solution Explorer (A pane should open on the right-side)
  • Click View -> Error List (A pane should open on the bottom)
  • Done, you are ready to set-up the RunUO Project!
__________________________________________________

#3

You should have a Start Page already open in the file view, infact, your VS should look like this by now; (SCREENSHOT)

If you don't have the Start Page open by default, you can still complete the following steps by using the File context menu.

__________________________________________________

#4

Creating a new project is simple, simply click Create: Project... in the Start Page - Recent Projects pane or click File -> New Project.

You will be confronted with a dialog menu that will ask you to select the type of project and a name for it; (SCREENSHOT)

Make sure you select Console Application and enter the name RunUO_Scripts (As shown in the image)

__________________________________________________

#5

You have successfully created a new project, but hold up, it isn't quite ready for your RunUO scripts!

You should be presented with a screen similar to this; (SCREENSHOT)

The first thing you need to do is DELETE the Program.cs from the Solution Explorer pane.

Click OK if prompted with "Program.cs will be deleted permanently".

__________________________________________________

#6

Now you need to set up the project Properties, these properties will determine things such as what the target .NET Framework should be, the default namespace of the project, etc...

To access the project properties, right-click on
RunUO_Scripts in the Solution Explorer and select Properties.

Do not be mis-guided by the Properties menu-item in the Solution Explorer pane, you won't need to mess with that.

__________________________________________________

#7

Before you continue, you must Save the current project, so that the changed properties can be saved correctly and so you can avoid any more annoying prompts.

Click File -> Save All.

You will be presented with another dialog asking you to select a working directory for your project and provide a name for it; (SCREENSHOT)

The default location will be (Windows XP) C:/Documents and Settings/<User>/My Documents/Visual Studio 2008/Projects/ OR (Windows Vista / 7) C:/Users/<User>/My Documents/Visual Studio 2008/Projects/ but for the purpose of this tutorial, I'm going to save it in C:/

Note that the "Create directory for solution" checkbox is checked, which means that the final path will be C:/RunUO_Scripts/.

Click Save.

__________________________________________________

#8

Now it's time to edit those properties, the list below describes the option name and the setting you should have;

Application Tab
  • Assembly Name: RunUO_Scripts
  • Default Namespace: Server
  • Target Framework: .NET Framework 2.0 ***
*** When prompted after changing the Framework version, just hit yes, the project will be saved and the Properties pane will be closed.
Repeat Step #6 to re-open the Properties pane.

Build Tab
  • Allow Unsafe Code: CHECKED - [X]
  • Optimize Code: CHECKED - [X]
Just leave everything else as their defaults for now...

Save and close the Properties pane.

__________________________________________________

#9

We are almost there, I promise!

All that is left to do now is edit the project references, this is extremely easy and impossible to mess up, so don't worry, really.

In the Solution Explorer pane, expand the References menu-item, it should look like this; (SCREENSHOT)

You will notice that 2 of the references are flagged as missing, this is because they are .NET 3.5 references and we don't need them in this .NET 2.0 project, so go ahead and remove them;
Right-click on the missing references and click Remove.

You now need to Add a couple references in order for your scripts to debug properly...

To add a standard reference, you must right-click on the References menu-item and click Add Reference.
You will be presented with a dialog with a few tabs along the top and a list of references to choose from, the references you need to add are found in the .NET tab, which should also be the default tab selected.

You need to add these references;
System.Windows.Forms, System.Drawing and System.Web

But wait, there's more...

We also need to create a custom reference to our RunUO.exe executable, which is extremely simple too;
You need to add another reference, but this time, it won't be in the .NET tab of the Add Reference dialog, you will have to click the Browse tab...

You need to browse to and select your RunUO.exe from wherver you store your RunUO shard...
When the custom reference has been added for the RunUO.exe, it will be automatically copied to your project's working directory.

Your references should look like this now; (SCREENSHOT)

Save the project, File -> Save All

__________________________________________________

#10

OK, everything is set to go!
But what about my scripts? I hear you ask, well this is the fun part;

Use Windows Explorer to navigate to your RunUO directory (The directory where you keep your Scripts and all things that are RunUO and your shard).

Now you're going to have to utilize those nifty drag-and-drop skills Windows has tought you over the month or years...

Select your Scripts directory and Drag it onto
RunUO_Scripts in the Solution Explorer pane inside Visual Studio.

Visual Studio should now begin the process of transferring all your RunUO scripts to your project's working directory, the end result should look like this; (SCREENSHOT)

Save the project, File -> Save All

__________________________________________________

DONE!

Everything is good to go, you are ready to start developing your scripts like a pro.

To test your project set-up, simply hit F5 to start debugging, or click the little green button that looks like a "play" icon on the top menu.

If you have NO ERRORS in your scripts and everything compiles successfully, you will receive this error in the Error List pane:
Code:
Program 'C:\RunUO_Scripts\RunUO_Scripts\obj\Debug\RunUO_Scripts.exe' does not contain a static 'Main' method suitable for an entry point.

This is expected.

__________________________________________________

Congratulations

Now just a couple notes for the future;
  • Whenever you change/edit and save a script in Visual Studio using your project, you will have to copy the edited script file from your project's working directory, over to your RunUO scripts directory for the changes to take effect in RunUO.
  • DO NOT add files to your project working directory from outside Visual Studio, because VS will not add the files to your project automatically, you should always use the drag-and-drop method when adding new files to your project.
  • The same goes for deleting files... Delete them from inside VS, or VS will not be too happy when it tries to load non-existant files.
__________________________________________________

Bonus References
I hope this tutorial was useful and not too hard for you to follow, if you have any comments, questions or sugestions, please don't hesitate to reply here!

-Vorspire
 

Attachments

  • VS01.jpg
    VS01.jpg
    160.2 KB · Views: 930
  • VS02.jpg
    VS02.jpg
    34.2 KB · Views: 691
  • VS03.jpg
    VS03.jpg
    120.6 KB · Views: 712
  • VSICON.jpg
    VSICON.jpg
    1.2 KB · Views: 2,099
  • VS04.jpg
    VS04.jpg
    19.5 KB · Views: 476
  • VS05.jpg
    VS05.jpg
    12.8 KB · Views: 650
  • VS06.jpg
    VS06.jpg
    14.3 KB · Views: 679
  • VS07.jpg
    VS07.jpg
    29.2 KB · Views: 661

Vorspire

Knight
KevinEvans;819724 said:
Even better, you can also reference /Script/Output/Scripts.CS.dll :)

Over 9000x to use :p

That is true, but it defies the point in having your RunUO Scripts as a solution for easy editing and would likely cause some problems, because there is always the possiblity that the file name can be appended with a number if the original Scripts.CS.dll failed to write.
IE: Scripts.CS1.dll (or similar format)

You would have to compensate for this by checking the the File Creation Dates of each file in the Output directory to see which one is the most recent, and then re-referencing that.

Don't forget that Visual Studio 2008 Express Edition automatically enables the CopyLocal option on custom references and may not update the local copy of the reference File, thus making your references inaccurate and possibly ambiguous in context.

Personally, I have a CSProject for both RunUO Core and Scripts in the same Solution with this build order;
RunUO Core -> Scripts

This allows me to both debug the RunUO Core and my custom Scripts folder, without having to recompile the Scripts.CS.dll by running RunUO.
The Custom Scripts project base directory is C:/RPK/Scripts/.
When the RunUO Core compiles, the output RunUO.exe goes to C:/RPK/, meaning I can run RunUO and keep everything synchronized.

When you run the debug process in VS, it is exactly the same as running RunUO.exe and letting it compile, except you have the benefit of and exceptionally powerful IDE that can help you detect and solve error problems easily.

Think of the Scripts.CS.dll file as more of a temporary cache file.
 

Attachments

  • VSCUSTOM.png
    VSCUSTOM.png
    115.1 KB · Views: 268

Jeff

Lord
What i do is have my Scripts project reference my Server Project so that editing scripts includes the Server classes intellisense. Then when i hit compile, it is setup to only compile the Server, and the server.exe is setup to build to the root directory of the project, this way the Scripts folder exist. When it runs Server.exe, it runs it with -debug, this way the Scripts.CS.dll is created with a Scripts.CS.pdb file and I can step into the Scripts code and use breakpoints as well. Of all the solutions I've tried this method allows me to do everything I want with as little modification and effort possible.
 

Vorspire

Knight
starlazer;819741 said:
bah notepad teaches you better to find your own mistakes, to backup regularly, and code right the first time

*goes back to basecreature.cs in notepad, still trying to find the } he accidentally deleted*

Actually, Notepad was designed for taking notes, it really doesn't teach you anything :p

If you're going to use Notepad to develop your scripts, then welcome to Hell, you're just making the job harder for yourself.

With an intelligent IDE, it will automatically point out the mistakes and also provide a tooltip telling you exactly why it is a mistake and how to fix it, there is no better development tutor than VS 2008.

There is also a plugin for VS called Visual Assist X, which can be found here;
http://www.wholetomato.com/downloads/default.asp
Visual Assist X does not currently support the Visual Studio Express Editions.
 

Vorspire

Knight
starlazer said:
is there a way to avoid having to copy the scripts you modified to your run uo directory and just modify the ones there?

Yes there is, it's a bit more complicated, otherwise I would have explained it in the main tutorial. :)

You can do one of two things;

#1:

You basically need to create the project using the path to your Scripts Directory as the working directory and uncheck "Create create directory for solution". ( Step #7 )

When you get to Step #10 You will still have to complete it, but since the project is already contained in your Scripts Directory it won't copy them or overwrite anything (in the File System).

#2:

Move your RunUO (entire shard) directory over to where you have created your project and execute your shard from that directory instead.

In reflection to the tutorial, the target path to copy your RunUO (entire shard) directory should be;
C:/RunUO_Scripts/RunUO_Scripts/
This includes the possibility of overwriting the project's Scripts Directory, I recommend that you click No for that.
 

Vorspire

Knight
Setharnas;820373 said:
I may be missing something, considering I've not really done anything with RunUO in ages, but is there any specific reason why you don't advise to configure the project as a Class Library instead of Console Application? Seems to be working just fine for me since VS2005... :)

(oh, and hi guys, long time no read :D)

It can be either/or Lib or Console. I prefer console, because I compile my Core first and I don't always want it to launch the compiled exe afterwards, which is why I prefer to receive the error.

Either way won't make a difference, as long as you can debug the scripts at your leisure :)
 

Xen-miao

Sorceror
HELLO MEN!



I've reached my personal goal so i wanted to say you how to do all the things i learned with your help!





This is important, else it doesn't work well.


Now go in the file "ScriptCompiler.cs" in the server core and modify this funcition

Code:
public static bool CompileCSScripts( bool debug, bool cache, out Assembly assembly )
		{
			Console.Write( "Scripts: Compiling C# scripts..." );
			string[] files = GetScripts( "*.cs" );

			if( files.Length == 0 )
			{
				Console.WriteLine( "no files found." );
				assembly = null;
				return true;
			}

			if( File.Exists( "Scripts/Output/Scripts.CS.dll" ) )
			{
				if( cache && File.Exists( "Scripts/Output/Scripts.CS.hash" ) )
				{
					try
					{
						byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.CS.dll", files, debug );

						using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.hash", FileMode.Open, FileAccess.Read, FileShare.Read ) )
						{
							using( BinaryReader bin = new BinaryReader( fs ) )
							{
								byte[] bytes = bin.ReadBytes( hashCode.Length );

								if( bytes.Length == hashCode.Length )
								{
									bool valid = true;

									for( int i = 0; i < bytes.Length; ++i )
									{
										if( bytes[i] != hashCode[i] )
										{
											valid = false;
											break;
										}
									}

									if( valid )
									{
										assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.CS.dll" );

										if( !m_AdditionalReferences.Contains( assembly.Location ) )
										{
											m_AdditionalReferences.Add( assembly.Location );
										}

										Console.WriteLine( "done (cached)" );

										return true;
									}
								}
							}
						}
					}
					catch
					{
					}
				}
			}

			DeleteFiles( "Scripts.CS*.dll" );

in this way

Code:
	public static bool CompileCSScripts( bool debug, bool cache, out Assembly assembly )
		{
			Console.Write( "Scripts: Compiling C# scripts..." );
			string[] files = GetScripts( "*.cs" );

			if( files.Length == 0 )
			{
				Console.WriteLine( "no files found." );
				assembly = null;
				return true;
            }
            #region xen
            /*if( File.Exists( "Scripts/Output/Scripts.CS.dll" ) )*/
            if (File.Exists("Scripts/Output/Scripts.dll"))
			{
				/*if( cache && File.Exists( "Scripts/Output/Scripts.CS.hash" ) )*/
                if(true)
				{
					//try
					/*{
						byte[] hashCode = GetHashCode( "Scripts/Output/Scripts.CS.dll", files, debug );

						using( FileStream fs = new FileStream( "Scripts/Output/Scripts.CS.hash", FileMode.Open, FileAccess.Read, FileShare.Read ) )
						{
							using( BinaryReader bin = new BinaryReader( fs ) )
							{
								byte[] bytes = bin.ReadBytes( hashCode.Length );

								if( bytes.Length == hashCode.Length )
								{
									bool valid = true;

									for( int i = 0; i < bytes.Length; ++i )
									{
										if( bytes[i] != hashCode[i] )
										{
											valid = false;
											break;
										}*/
					//				}

									/*if( valid )*/
                                    if(true)
									{
										/*assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.CS.dll" );*/
                                        assembly = Assembly.LoadFrom( "Scripts/Output/Scripts.dll" );
										if( !m_AdditionalReferences.Contains( assembly.Location ) )
										{
											m_AdditionalReferences.Add( assembly.Location );
										}

										Console.WriteLine( "done (cached)" );

										return true;
									}
								}
							}
						//}
				//	}
				//	catch
				//	{
				//	}
		//		}
            //}
            #endregion
            DeleteFiles( "Scripts.CS*.dll" );

As you can see i didn't modify too much, i just substued some text. However in this way your VS will be linked to your DLL. What does it change?
Easy:
1) Less time spent compiling code (because you'll do it just once with your VS)
2) Less time spent debugging code because you'll have full access with all VS resources.
3) Better writing programs because your debug will be easier then ever.


See you guys and thank you a lot for your help!
 

Jeff

Lord
Only point 1 is valid. Point 2 and 3 should have already been true had the project been setup properly. Also, you have to setup a command line argument for the server when you debug for debug mode (-debug) otherwise it will not create the PDB file when the server compiles the scripts thus not allowing you to step into the script code.
 

nibbio

Sorceror
i've done this small simple program that build related hash file of the compiled dll...
with it, you can make a valid hash file for jump double compile from runuo.exe and visual c#.
Runuo simply see a cached dll every time you compile with visual c#.

it doesn't check name, similar than "Scripts.CS{}.dll, but you can implement that modification easily.

this program take these arguments:

1) solution path
2) debug parameter

example: HashMaker C:\Runuo\ -debug
where C:\Runuo is the main directory of Runuo Server, and contains /Scripts/ etc....

In Visual c# you can use this program, with a custom post-build event.

In the properties of script project, you can add a simple macro, like this:

$(SolutionDir)HashMaker $(SolutionDir) -$(ConfigurationName)

In my case, HashMaker is in main solution directory, but you can simply change it's location.

I hope this program helps some of you.

View attachment 18304
 

Attachments

  • HashMaker.rar
    34.7 KB · Views: 22
Visual Studio 2010 supports .NET 4.0 which is pretty neat. Apart from that changes are rather small. I got the impression that the new VS is a bit more responsive but I can't be certain. Since I was using ReSharper before there aren't any great new features that haven't been there with ReSharper before. But everyone else will get some small but exciting new features.

To sum it up: if you're only developing for RunUO and you're not planning on switching to .NET 4.0, getting the new version isn't really necessary.

What's New in Visual Studio 2010
 

Peoharen

Sorceror
I see 10 steps to set up Express to handle what is effectively grammar errors. I see advice to do a core edit to disable script caching. Good intentions no doubt, but how can someone set up Express if they cannot fix "target" to "Caster" or w/e?

Here is a preliminary guide for Notepad++

Installing
1.
Download Notepade++ [/ur=http://notepad-plus-plus.org/downloadl]here[/url] and install it.

2.
Use open, drop a file into, or hey hold shift and right click on a .cs file and assign Notepad++ to open it for you, w/e. Hey, you are already editing files without all kinds of mandatory setup.


Features

Replace
Did you copy a lot of or sections of multiple code and it is using different variable names than you are? IE "Caster" but you are using "target"? Notepad++ can replace all instances of one word with another allowing instant renaming.

Winmerge
No it's not winmerge but Notepad++ can do it. Use it's compare feature and merge files properly and in a single program.

Tabbing
Notepad++ uses tab instead of the retarded 4 space setup Express uses. As a result of not using 4 space characters per tab your total file size will be reduced by no less than 400%. This means less filestream to read leading to faster compile times, less HD usage, and so on.

Sentax Highlighting
Notepad++ by default highlights C# keywords & types. You can set up your own user define highlighting to handle RunUO's types. If you do then you should post it for others to use.

Backups
Notepad++ can proform autoback ups too.

Addons
You know why firefox kicks IEs ass? Well besides being better in every way, addons. Notepad++ has them. Go check them out, hell post your custom code highlight file for RunUO there too.

It works
Doesn't require a dedicated post to getting it to work. Yeah, this post doesn't do a thing to help you use Notepad++, you can already use it and there is no needed walk througs needed to even get to this point.

The last feature of Notepad++ is something most here have no use for. You don't need download three version of Express and use the different programs just to support the three main languages .NET was meant to be used with (VB, C++, C#). HTML, CSS, Java, Python, C#, SQL, you name it., it works for other languages.

FAQ
Q: How do I disable script caching?
A: Without editing core, that's for sure. Create a shortcut for the server and rightclick>props on it. In the target box after the quotes put in -nocache.

Q: How do I enable debug?
A: See caching only this time is -debug.

Q: Can I do both?
A: Of course.

Q: Is Notepad++ better than Express?
A: Depends.
For learning? Heck yeah, Express is almost a code generator and I forgot whos sig it was but it says it best. "Code Generators are dumb", you don't learn a thing by using them.
For editing? Honestly no matter what computer you are on, Notepad++ loads up and opens the file in a fraction of the time it takes Express to simply open. There is no such thing as making a fast edit with Express. I'd award Notepad++ for this, some times you just need top open a file and delete an accidental extra 0 to something.
For debugging? This may go to Express, without a user-defined highlight the best Notepad++ can do is mouse highlighting a word which highlights all other instances of that word. Useful to spot typos since Moible won't turn green. Express on the other hand should color in Mobile once it's setup (see the 10 steps above for that).
 

Vorspire

Knight
Peoharen;847887 said:
I see 10 steps to set up Express to handle what is effectively grammar errors.

Reference errors and all other exceptions are also detected.

Peoharen;847887 said:
...but how can someone set up Express if they cannot fix "target" to "Caster" or w/e?

I'm sure you read the first post?

Peoharen;847887 said:
Features

Replace
Did you copy a lot of or sections of multiple code and it is using different variable names than you are? IE "Caster" but you are using "target"? Notepad++ can replace all instances of one word with another allowing instant renaming.

VCSExpress can do this too, but better. It can rename every instance of any reference or word in the entire project and also has sub-features allowing wild-cards and regular expressions.

Peoharen;847887 said:
Winmerge
No it's not winmerge but Notepad++ can do it. Use it's compare feature and merge files properly and in a single program.

Granted one feature that I'm not sure exists in VCSExpress.

Peoharen;847887 said:
Tabbing
Notepad++ uses tab instead of the retarded 4 space setup Express uses. As a result of not using 4 space characters per tab your total file size will be reduced by no less than 400%. This means less filestream to read leading to faster compile times, less HD usage, and so on.

So you've never found the "Show advanced options" check-box and edited the IDE settings for smart-tabbing in VCSExpress? I did.

Peoharen;847887 said:
Sentax Highlighting
Notepad++ by default highlights C# keywords & types. You can set up your own user define highlighting to handle RunUO's types. If you do then you should post it for others to use.

VCSExpress has one of the most powerful built-in IDE's where syntax highlighting is only one of many sub-features.

Peoharen;847887 said:
Backups
Notepad++ can proform autoback ups too.

VCSExpress offers this feature too, mine also comes with a roll-back option.

Peoharen;847887 said:
Addons
You know why firefox kicks IEs ass? Well besides being better in every way, addons. Notepad++ has them. Go check them out, hell post your custom code highlight file for RunUO there too.

IE, FireFox and Chrome all support extensions/addons/plugins.
So does VCSExpress, I had an addon called VisualStudioX that offered advanced IDE highlighting and auto-completion.

Peoharen;847887 said:
It works
Doesn't require a dedicated post to getting it to work.

It's just a simple plug-and-play application, what do you expect?
Yet you still made a post explaining n how to get it to work?

Peoharen;847887 said:
Yeah, this post doesn't do a thing to help you use Notepad++, you can already use it and there is no needed walk througs needed to even get to this point.

Of course, the title of this post is "The Perfect Solution [Visual Studio 2008]", not "The Almost-Perfect Solution [NotePad++]"

Peoharen;847887 said:
The last feature of Notepad++ is something most here have no use for. You don't need download three version of Express and use the different programs just to support the three main languages .NET was meant to be used with (VB, C++, C#). HTML, CSS, Java, Python, C#, SQL, you name it., it works for other languages.

That's odd, because I used to use my VCSExpress to edit all of those above listed files, granted not all had IDE support. I then got Visual Studio 2010 Ultimate which edits every file under the sun.

Peoharen;847887 said:
FAQ
Q: Is Notepad++ better than Express?
A: Depends.
For learning? Heck yeah, Express is almost a code generator and I forgot whos sig it was but it says it best. "Code Generators are dumb", you don't learn a thing by using them.
For editing? Honestly no matter what computer you are on, Notepad++ loads up and opens the file in a fraction of the time it takes Express to simply open. There is no such thing as making a fast edit with Express. I'd award Notepad++ for this, some times you just need top open a file and delete an accidental extra 0 to something.

First off, VCSExress is anything BUT a code generator, you actually have to write the code that shows in the auto-complete and second, you still have to write out code snippets that you use.
Nothing is "generated" without first manually writing the code.
I'm pretty sure you DO learn how to use the application by actually using the application...
VCSExpress is tagged Express for a reason, it load fast when opening one, to or even fifty files at once and is very portable. The only time it ever loads slowly is when it's loading an entire projects with a couple thousand files in it, this makes me think that you must need a RAM upgrade..

Visual Studio simply cannot be defeated, I assume Microsoft developers use it themselves.

However, having made all those points, it is still nice to have another light-weight editor for use with non-development related file editing, so I did after all decide to install NotePad++.
 

david6

Sorceror
Hi i did all of your steps but when i try to debug i get an error message : There were build errors. Would you like to continue and run the last successful build?
Yes no

i press yes and get this error
Visual studio cannot start debugging because the debug target c/users/david/documents/visualstudio 2010/projects/run uo_scripts/Runuo_scripts/bin/debug/runuomondains.exe is missing. please build the project and retry
 

MIKTHEBUG

Sorceror
i got almost the same error as above

Error 1 Program 'C:\RunUo\RunUo_Scripts\RunUo_Scripts\obj\x86\Debug\RunUo_Scripts.exe' does not contain a static 'Main' method suitable for an entry point RunUo_Scripts
 
Top